Splunk Search

Percentage calculation based on derived value and show it is as new row

deepa_purushoth
Engager

My data looks something like below, here first two rows are indexed data and 3,4th rows are derived data and added as new rows after some manipulation. My question is i want to add one more new row as by calculating percentage. for example - between rows 2 & 3 or 3&4 .

column1| column2
XXX| 10
YYY|20
abc|30
efg|10

Outcome something like
column1| column2
XXX| 10
YYY|20
abc|30
efg|10
per|33 ( ie., (column1=efg/column1=abc)*100

Please help. thanks

Tags (1)
0 Karma

niketn
Legend

@deepa_purushothaman, for the description provided, I am expecting two columns and four rows in your data, where you want percent to be calculated based on 3rd and 4th row. Try the following run anywhere which mimics your data as per question. Commands till | table column1 column2 generate sample data, you would need to plug in your existing query which generates first table as per your question.

| makeresults
| eval data="XXX|10;YYY|20;abc|30;efg|10"
| makemv data delim=";"
| mvexpand data
| eval data=split(data,"|")
| eval column1=mvindex(data,0)
| eval column2=mvindex(data,1)
| table column1 column2
| transpose header_field=column1 column_name=column1
| eval perc=round((efg/abc)*100,1)
| transpose header_field=column1 column_name=column1

PS: This example uses transpose to invert the sample table in the question and perform calculation as needed. If you can share your current search query community might be able to assist you with better query by avoiding multiple transpose. Ideally you perform event related calculation in the same row and then convert to column if required.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...