Splunk Search

Average of unknown number of fields

helge
Builder

I have an unknown number of fields with similar names, e.g. field1, field2, field3, etc.

I need the average of all values from all fields. I tried to use a wildcard:

avg(field*)

But that gives me the averages of each field individually:

avg(field1) avg(field2) avg(field3) ...

This does not work either (no results):

avg(avg(field*))

Is there a way to get the average of all fields in a single value?

Tags (2)
1 Solution

lguinn2
Legend

Try this:

yoursearchhere
| stats sum(field*)  count(field*)
| addtotals fieldname=Sum sum*
| addtotals fieldname=Count count*
| eval Average = Sum / Count

I am not sure if it will work. I wasn't able to try it. But I think that the addtotals command will help.

View solution in original post

lguinn2
Legend

Try this:

yoursearchhere
| stats sum(field*)  count(field*)
| addtotals fieldname=Sum sum*
| addtotals fieldname=Count count*
| eval Average = Sum / Count

I am not sure if it will work. I wasn't able to try it. But I think that the addtotals command will help.

helge
Builder

Awesome, thanks!

0 Karma
Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Dynamic formatting from XML events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  🚀 Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...