Splunk Search

Sum or count by same value

rsokolova
Path Finder

Thanks in advance.

We are trying to sum two values based in the same common key between those two rows and for the ones missing a value should be considered as a cero, to be able to sum both fields (eval Count=Job_Count + Request_Count) . alt text

Expected result should be:
PO_Ready Count
006341102527 5
011561102529 5
011971102529 6
012381102528 5

Tags (4)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi rsokolova,
If you always have only one between Job_Count and Request_Count, you can try something like this:

your_search
| eval Count=coalesce(Job_Count,Request_Count)
| stats sum(Count) AS Count BY PO_Ready 

otherwise if you have for a PO_Ready both Job_Count and Request_Count, you can try something like this:

your_search
| stats sum(Job_Count) AS Job_Count sum(Request_Count) As Request_Count BY PO_Ready 
| eval Count=Job_Count + Request_Count 
| table PO_Ready Count

Bye.
Giuseppe

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi rsokolova,
If you always have only one between Job_Count and Request_Count, you can try something like this:

your_search
| eval Count=coalesce(Job_Count,Request_Count)
| stats sum(Count) AS Count BY PO_Ready 

otherwise if you have for a PO_Ready both Job_Count and Request_Count, you can try something like this:

your_search
| stats sum(Job_Count) AS Job_Count sum(Request_Count) As Request_Count BY PO_Ready 
| eval Count=Job_Count + Request_Count 
| table PO_Ready Count

Bye.
Giuseppe

rsokolova
Path Finder

Thanks cusello for the quick reply the coalesce command did the trick.

0 Karma
Get Updates on the Splunk Community!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...