Splunk Search

Sum of count conditionally within a query

dcavag001c
New Member

I have incoming calls and I'm trying to get total number of calls followed by sum of calls where the field "result" equals declined, caller_ended, or callee_ended. I'm able to get the sum(count) but for the second part I am only getting a count of the events when really I want to sum the count.

How can I get a sum of the field count where result is equal to "callee_ended", "caller_ended" or "declined" without filtering the first part of the query

|stats sum(count) as NumberofCalls , sum(eval(if((result = "declined" OR result = "caller_ended" OR result = "callee_ended"), count, NULL))) AS SuccessfulCalls

Tags (1)
0 Karma
1 Solution

somesoni2
Revered Legend

Try like this

your base search | eval successcalls=if(result = "declined" OR result = "caller_ended" OR result = "callee_ended",count,null()) | stats sum(count) as NumberofCalls, sum(successcalls) as SuccessfulCalls

View solution in original post

0 Karma

somesoni2
Revered Legend

Try like this

your base search | eval successcalls=if(result = "declined" OR result = "caller_ended" OR result = "callee_ended",count,null()) | stats sum(count) as NumberofCalls, sum(successcalls) as SuccessfulCalls
0 Karma

dcavag001c
New Member

Thanks for your response but that still only returns the count of events with those parameters rather than a sum(count) with those parameters.

0 Karma

somesoni2
Revered Legend

That should've worked, I've setting the value of successcall to count when your result value follows those condition. Could you post the query that you tried, possibly full query?

0 Karma

dcavag001c
New Member

Sorry about that. The query I was using to check the count was incorrect. Your query works! Sorry for the confusion.

0 Karma
Get Updates on the Splunk Community!

Index This | Why did the turkey cross the road?

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

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...