Splunk Search

Need something like addtotals(sum across columns) for calculating average across columns

hmahendrakumar
Path Finder

I want to compute average across columns for a table(that I get as a result from stats command). I am trying to do somrthing similar to addtotals(sum) but for average. I can of course use addtotals and divide it by no of columns to get the average. But, number of columns vary on a row by row basis.

For eg:-

......... Col1 Col2 Col3 Avg

Row1 .... 2 .. 3 .. 4 .... 3

Row2 .... ..... 3 .. 5 .... 4

Row3 .... ........... 5 .... 5

Tags (1)
0 Karma
1 Solution

MartinHarper
Path Finder
0 Karma

MartinHarper
Path Finder
0 Karma

gkanapathy
Splunk Employee
Splunk Employee

Seems to me that you'd have to come up with the count of the non-null columns:

eval col_count=if(isnull(col1,0,1))+if(isnull(col2,0,1))+if(isnull(col3,0,1))

Either that, or it might not be a bad idea to rethink how the stats command is being done. There might be better ways to get the result you want.

hmahendrakumar
Path Finder

This would work if you roughly know the no of columns . What if we don't know the number of cols before ?

0 Karma
Get Updates on the Splunk Community!

Index This | When is October more than just the tenth month?

October 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

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 & Next in Splunk SOAR

 Security teams today are dealing with more alerts, more tools, and more pressure than ever.  Join us for an ...