Splunk Search

Combine values from mutliple rows

magriii
Explorer

Goal is to subtract file counts of folders from sites MAIN and BACK.

Sample data

 

| makeresults
| eval f="MAIN-AAA", val="17313"
| append [| makeresults | eval f="BACK-AAA", val="17357"]
| append [| makeresults | eval f="MAIN-BBB", val="682"]
| append [| makeresults | eval f="BACK-BBB", val="682"]
| append [| makeresults | eval f="MAIN-CCC", val="38767"]
| append [| makeresults | eval f="BACK-CCC", val="38804"]
| eval site=substr(f,1,4) | eval folder=substr(f,6)

 

Output should be something like

 

folder,count MAIN,count BACK,difference
AAA,17313,17357,4
BBB,682,682,0
CCC,38804,38767,37

 

thanks

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| eval countMAIN=if(site="MAIN",val,NULL())
| eval countBACK=if(site="BACK",val,NULL())
| fields countMAIN, countBACK, folder
| stats values(*) as * by folder
| eval difference=abs(countMAIN-countBACK)

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust
| eval countMAIN=if(site="MAIN",val,NULL())
| eval countBACK=if(site="BACK",val,NULL())
| fields countMAIN, countBACK, folder
| stats values(*) as * by folder
| eval difference=abs(countMAIN-countBACK)
Get Updates on the Splunk Community!

Data Management Digest – December 2025

Welcome to the December edition of Data Management Digest! As we continue our journey of data innovation, the ...

Index This | What is broken 80% of the time by February?

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

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...