Splunk Search

Could you introduce and use dynamic statistics in eval commands?

DouglasSmithers
Engager

I'm trying to calculate an average column in a chart by renaming the Total column (created with the addtotals command) and diving it by the number of columns summed by addtotal, but the average will change as new events are added so I wouldn't prefer to simply use the current average, as that would require routinely updating the code. Is there a way to create the average within the eval command so that it would update automatically as new data is added? It would simply require that the Average (formerly Total) column would be divided by a distinct count of one of the categories being analysed.

I won't post all of the code in my search, as, at this point, I've created a chart, transposed it, appended a column, added totals and altered them with eval, and repeated that last step to different effect (I'm quite a way through a dashboard at this point). The last snippet of code which describes the current point is as follows.

| table pWeekInQuarter 1 2 3 4 5 6 7 8 9 10 11 12 13
| addcoltotals labelfield="pWeekInQuarter" label="Average"
| transpose column_name=pWeekInQuarter header_field=pWeekInQuarter 0
| eval "Average"=$Average$/[search index=breakdown | stats dc($pQuarter$)]

In the last line, you can see a subsearch to pull the statistic required for the average. That, however, wouldn't work. It is where that subsearch is, following the slash, that I need to place an actively updated statistic.

Tags (1)
0 Karma

mayurr98
Super Champion

Hi it would better to solve your problem if you update your question with the search query you are using currently, o/p you are getting and the expected o/p?

0 Karma

DouglasSmithers
Engager

Sure. I won't post all of the code in my search, as, at this point, I've created a chart, transposed it, appended a column, added totals and altered them with eval, and repeated that last step to different effect (I'm quite a way through a dashboard at this point). The last snippet of code which describes the current point is as follows.

| table pWeekInQuarter 1 2 3 4 5 6 7 8 9 10 11 12 13
| addcoltotals labelfield="pWeekInQuarter" label="Average"
| transpose column_name=pWeekInQuarter header_field=pWeekInQuarter 0
| eval "Average"=$Average$/[search index=breakdown | stats dc($pQuarter$)]

In the last line, you can see a subsearch to pull the statistic required for the average. That, however, wouldn't work. It is where that subsearch is, following the slash, that I need to place an actively updated statistic.

Is that enough information?

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!

.conf25 Global Broadcast: Don’t Miss a Moment

Hello Splunkers, .conf25 is only a click away.  Not able to make it to .conf25 in person? No worries, you can ...

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...