Splunk Search

sum of 2 possible fields

lanilim16
Explorer

The search result looks like this
<date>, COUNT_SENT=20, SUM_AMOUNT=50000
<date>, COUNT_RECEIVED=30, SUM_AMOUNT=10000

I need to get the total for both (COUNT_SENT + COUNT_RECEIVED) by hour, but this doesn't since they're in different events

This doesn't work

<search string> | eval total = COUNT_SENT + COUNT_RECEIVED | stats sum(total) by hour

rename doesn't work too.

I manage to only sum either the COUNT_SENT or COUNT_RECEIVED separately but not combined, I need the combined though.

Tags (3)
0 Karma

bmacias84
Champion

This should work

.... | bucket _time span=1h | stats sum(COUNT_SENT) as tcs sum(COUNT_RECEIVED) as tcr by _time | eval total=tcs+tcr
0 Karma

jnussbaum_splun
Splunk Employee
Splunk Employee

try - | bucket _time span=1h | stats sum(eval(COUNT_SENT+COUNT_RECEIVED)) AS test by _time

0 Karma

woodcock
Esteemed Legend

Like this:

... | stats sum(COUNT_SENT) AS COUNT_SENT sum(COUNT_RECEIVED) AS COUNT_RECEIVED BY hour | eval total = COUNT_SENT + COUNT_RECEIVED
0 Karma
Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Dynamic formatting from XML events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

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

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...