Splunk Search

Apply different calculation count/sum depending on value/index

martinmasif
Explorer

I have a "cost" for two different indexes that I want to calculate in one and the same SPL. As the "price" is different depending on index, I can't just use a "by" clause in my count/sum as I don't know how to apply the separate costs in that way.

Let's say...

idxCheap costs $10 per event.

idxExpensive costs $20 per event.

I've written this SPL that works, although the "cost" data ends up in a unique column for each index. The count is still in the same column.

index=idxCheap OR index=idxExpensive
| stats count by index
| eval idxCheapCost = case(index="idxCheap", count*10)
| eval idxExpensiveCost = case(index="idxExpensive", count*20)

 The results looks like this:

count idxCheapCost idxExpensiveCost index

44892448920 idxCheap
155 3100idxExpensive

 

Any pointers on how to most efficiently and dynamically achieve this?

Labels (2)
Tags (2)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

You're close.  Combine the case functions to produce a single expense field.

index=idxCheap OR index=idxExpensive
| stats count by index
| eval idxCost = case(index="idxCheap", count*10, index="idxExpensive", count*20)

 

---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

You're close.  Combine the case functions to produce a single expense field.

index=idxCheap OR index=idxExpensive
| stats count by index
| eval idxCost = case(index="idxCheap", count*10, index="idxExpensive", count*20)

 

---
If this reply helps you, Karma would be appreciated.

martinmasif
Explorer

Haha why did I even split it up on two rows?!

Thanks!

 

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

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

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...