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!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...