Splunk Search

Diff and % calculation 1st row vs 2nd row

puneethgowda
Communicator

alt text

source=DAM_DB_SUMMARY_REPORT | eval Date=substr(DATES,1,10) | stats sum(TOTAL_RECORDS) as "Total Records" by Date | sort - Date

i would like to insert one column that should be DIFF and calculation should be subtraction ( Row 1 - row 2) row 1 value us 797,775 and row 2 value is 797,774 so 3rd new column value should be 1. and also we need % in 3rd column 1/797,775 (diff/1st row count)

Tags (1)
0 Karma
1 Solution

Richfez
SplunkTrust
SplunkTrust

I thought this for sure was going to be a streamstats answer, but instead it's far easier to use delta.

You should be able to just add | delta "Total Records" to the end of your search, like

source=DAM_DB_SUMMARY_REPORT | eval Date=substr(DATES,1,10) | stats sum(TOTAL_RECORDS) as "Total Records" by Date | sort - Date | delta "Total Records"

Can you give that a go and report back?

Happy Splunking!
Rich

View solution in original post

Richfez
SplunkTrust
SplunkTrust

I thought this for sure was going to be a streamstats answer, but instead it's far easier to use delta.

You should be able to just add | delta "Total Records" to the end of your search, like

source=DAM_DB_SUMMARY_REPORT | eval Date=substr(DATES,1,10) | stats sum(TOTAL_RECORDS) as "Total Records" by Date | sort - Date | delta "Total Records"

Can you give that a go and report back?

Happy Splunking!
Rich

puneethgowda
Communicator

thanks a lot

0 Karma

puneethgowda
Communicator

sorry it was very simple i have got this after posting here forgot to upfdate

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...