Splunk Search

calculate difference for each group

5296
Loves-to-Learn Lots
actionfeatureversionlocationcount?difference?
Af1v1WA1200
Af1v1OR11010
Af1v1CA1155
Bf1v1AZ1200
Af1v2WA141
Af1v2OR105
Bf1v2AZ150


I got a table of info above: action, feature, version, location, and count.  Could anyone help me to find the last column "difference" here?  

A group is identified by same feature and version combination. so in the example table, the first four rows(f1+v1) are one group, and the last three rows(f1+v2) are the second group. 
within each group, difference = count B - count A.  
 for example:
row1, difference = count (B, f1, v1, AZ) - count (A, f1,v1,WA) = 120-120=0
row2, difference = count (B, f1, v1, AZ) - count (A, f1,v1,OR) = 120-110=10
difference of countB itself is 0.

Labels (6)
0 Karma

renjith_nair
Legend

You may try

"Your current search"
|eventstats max(eval(if(action=="B",count,null()))) as action_b by feature,version
|eval difference=action_b - count

 

Run anywhere example

| makeresults |eval action="A A A B A A B"|makemv action|mvexpand action
|appendcols[|makeresults |eval feature="f1 f1 f1 f1 f1 f1 f1"|makemv feature| mvexpand feature]
|appendcols[|makeresults |eval version="v1 v1 v1 v1 v2 v2 v2"|makemv version| mvexpand version]
|appendcols[|makeresults |eval location="WA OR CA AZ WA OR AZ"|makemv location| mvexpand location]
|appendcols[|makeresults |eval count="120 110 115 120 14 10 15"|makemv count| mvexpand count]
|fields - _time
|rename COMMENT as "Ignore above data similution search"
|eventstats max(eval(if(action=="B",count,null()))) as action_b by feature,version
|eval difference=action_b - count
|fields action,feature,version,location,count,difference

 

---
What goes around comes around. If it helps, hit it with Karma 🙂
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...