Splunk Search

How to calculate the average in the total row?

boxmetal
Path Finder

Hi Splunk community,

I need to display data shown as table below

Component Total units Violated units Matched [%]
Type A 1 1 99
Type B 10 10 75
Type C 100 85 85
Total 111 96 86

 

In the total row, the matched value is the average of the column, while others are the sum value.

Is it possible to insert the average value to the total row as shown?

Here's my SPL:

 

index="my_index"source="*sourcename*"
| stats count as total_units count(eval(isnull(approval_message))) as violated_units values(matched_percentage) as matched by component 
| addcoltotals total_units + violated_units labelfield=component
| rename total_units as "Total Units", violated_units as "Violated Units", matched as "Matched [%]"

 

 

 

Labels (1)
0 Karma
1 Solution

Manasa_401
Communicator

Hello @boxmetal 

Try the below query:

index="my_index"source="*sourcename*"
| stats count as total_units count(eval(isnull(approval_message))) as violated_units values(matched_percentage) as matched by component 
| addcoltotals total_units + violated_units labelfield=component
| streamstats avg(matched) as average
| eval matched=coalesce(matched,average)
| fields - average
| rename total_units as "Total Units", violated_units as "Violated Units", matched as "Matched [%]"


If this helps an upvote would be appreciated.

Thanks,

Manasa

View solution in original post

boxmetal
Path Finder

Hi @Manasa_401 ,

The table showed average calculation. Thank you a lot!

0 Karma

Manasa_401
Communicator

Hello @boxmetal 

Try the below query:

index="my_index"source="*sourcename*"
| stats count as total_units count(eval(isnull(approval_message))) as violated_units values(matched_percentage) as matched by component 
| addcoltotals total_units + violated_units labelfield=component
| streamstats avg(matched) as average
| eval matched=coalesce(matched,average)
| fields - average
| rename total_units as "Total Units", violated_units as "Violated Units", matched as "Matched [%]"


If this helps an upvote would be appreciated.

Thanks,

Manasa

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Introduction to Splunk AI

How are you using AI in Splunk? Whether you see AI as a threat or opportunity, AI is here to stay. Lucky for ...

Splunk + ThousandEyes: Correlate frontend, app, and network data to troubleshoot ...

Are you tired of troubleshooting delays caused by siloed frontend, application, and network data? We've got a ...

Maximizing the Value of Splunk ES 8.x

Splunk Enterprise Security (ES) continues to be a leader in the Gartner Magic Quadrant, reflecting its pivotal ...