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!

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

 Prepare to elevate your security operations with the powerful upgrade to Splunk Enterprise Security 8.x! This ...

Get Early Access to AI Playbook Authoring: Apply for the Alpha Private Preview ...

Passionate about security automation? Apply now to our AI Playbook Authoring Alpha private preview ...

Reduce and Transform Your Firewall Data with Splunk Data Management

Managing high-volume firewall data has always been a challenge. Noisy events and verbose traffic logs often ...