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!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Preparing your Splunk Environment for OpenSSL3

The Splunk platform will transition to OpenSSL version 3 in a future release. Actions are required to prepare ...

Self-Healing Pipeline Is Now Generally Available: AI-Powered CIM Compliance

Maintaining data integrity across security and analytics pipelines is an ongoing challenge. Data ...