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
Get Updates on the Splunk Community!

Building Reliable Asset and Identity Frameworks in Splunk ES

 Accurate asset and identity resolution is the backbone of security operations. Without it, alerts are ...

Cloud Monitoring Console - Unlocking Greater Visibility in SVC Usage Reporting

For Splunk Cloud customers, understanding and optimizing Splunk Virtual Compute (SVC) usage and resource ...

Automatic Discovery Part 3: Practical Use Cases

If you’ve enabled Automatic Discovery in your install of the Splunk Distribution of the OpenTelemetry ...