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 | Why did the turkey cross the road?

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

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  &#x1f680; Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...