Splunk Search

How to make a calculated field?

zbsplunker
Engager

I am trying to figure out a way to calculate a field in a set of data. In my search im returned events from a long list of computers. For lack of a better explanation, I have events that essentially each computer will throw once a day at the same time every day. I will have logs that have fields ComputerName, and ComputerValue. Every day the ComputerValue will be a different numeric value. I need to create a new field in each log that will be the difference between the ComputerValue field. So if day 1, Computer1 gives ComputerValue 10, and day 2 Computer1 gives ComputerValue 12, I need to at search time add a field to Computer1 that would be day 2 value minus day 1 value positive or negative. So day 2 will also have a value ComputerDifference of 2. and if day 3 computerValue is 8, it would be ComputerValue of day 2 minus day 3 and ComputerDifference would be -4.

Its something I could easily do in Excel but I cant figure out a way to do it here. Any suggestions? 

Labels (4)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

| sort 0 _time
| streamstats window=1 current=f global=f values(ComputerValue) as PreviousComputerValue by ComputerName
| eval diff=ComputerValue-PreviousComputerName

View solution in original post

zbsplunker
Engager

Dang thanks, never used streamstats this is great

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

| sort 0 _time
| streamstats window=1 current=f global=f values(ComputerValue) as PreviousComputerValue by ComputerName
| eval diff=ComputerValue-PreviousComputerName
Get Updates on the Splunk Community!

.conf25 Community Recap

Hello Splunkers, And just like that, .conf25 is in the books! What an incredible few days — full of learning, ...

Splunk App Developers | .conf25 Recap & What’s Next

If you stopped by the Builder Bar at .conf25 this year, thank you! The retro tech beer garden vibes were ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...