Splunk Search

How to sum values in a table with a condition that compares columns?

HeinzWaescher
Motivator

Hi,

I've got a table like this

ts1 | ts2 | count  | id
1461347440 | 1461347448 | 5 | 1234
1461347459 | 1461347452 | 10 |  1234
1461347455 | 1461347459 | 10 |  7899

I would like to sum "count" if ts1<=ts2, for each id. My approach looks like this, but it seems to fail because of the field comparison

 | eventstats sum(eval(if(ts1<ts2, count, null()))) AS sum BY Id

Can you help me to get the wanted calculation?

Thanks in advance
Heinz

1 Solution

woodcock
Esteemed Legend

Whenever you try to add null, you will trash your field so use 0 instead:

| eventstats sum(eval(if(ts1<ts2, count, 0))) AS sum BY Id

View solution in original post

0 Karma

woodcock
Esteemed Legend

Whenever you try to add null, you will trash your field so use 0 instead:

| eventstats sum(eval(if(ts1<ts2, count, 0))) AS sum BY Id
0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...