Splunk Search

How to calculate the total number as Excel?

diag
New Member

here is an example of the table.   

 

  X Y Z W
A8 2      
B12   7   5
C14 5      
D24   2 3  
Total 2*8+5*14 7*12+2*24 3*24 5*24

 

 What is the SPL (formula or command) for calculating the total number as listed in the table? 

 

 

Thanks,

 

 

Labels (1)
Tags (1)
0 Karma

diag
New Member

It really helped me understand the SPL. 

0 Karma

bowesmana
SplunkTrust
SplunkTrust

Assuming you have this data in Splunk and the field names are A_ X Y Z W, this examples shows how using your data, which you can copy/paste into a search

| makeresults
| eval _raw="A 	X	Y	Z	W
A8	2	 	 	 
B12	 	7	 	5
C14	5	 	 	 
D24	 	2	3"
| multikv forceheader=1
| table A_ X Y Z W
``` Above reproduces your table ```

``` Get the multiplier from the first field ```
| rex field=A_ "[A-Z](?<mul>\d+)"
``` Now Multiuply the field value by the multiplier ```
| foreach X Y Z W [ eval <<FIELD>>=<<FIELD>>*mul ]
| fields - mul
``` and create the column totals ```
| addcoltotals

 I am assuming your final column total for col W is not correct, but should read 5 * 12?

 

0 Karma
Get Updates on the Splunk Community!

Index This | When is October more than just the tenth month?

October 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Observe and Secure All Apps with Splunk

  Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What’s New & Next in Splunk SOAR

 Security teams today are dealing with more alerts, more tools, and more pressure than ever.  Join us for an ...