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!

Introducing Value Insights (Beta): Understand the Business Impact your organization ...

Real progress on your strategic priorities starts with knowing the business outcomes your teams are delivering ...

Enterprise Security (ES) Essentials 8.3 is Now GA — Smarter Detections, Faster ...

As of today, Enterprise Security (ES) Essentials 8.3 is now generally available, helping SOC teams simplify ...

Unlock Instant Security Insights from Amazon S3 with Splunk Cloud — Try Federated ...

Availability: Must be on Splunk Cloud Platform version 10.1.2507.x to view the free trial banner. If you are ...