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!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...