Splunk Search

Stats sum function

Michael_Schyma1
Contributor
index=hig `sourcetype="MainframeApps"  |stats sum(count)|top limit=0  app_id app_name | fields + count, total_count,  percent,app_name, app_id | accum count AS total_count | rename total_count AS "Total Count" app_id AS "App Code" app_name AS "Application Name" count AS "Number of Events" percent AS "Percent"

I can not figure out why i can not get the sum function to work? any suggestions

Tags (1)
0 Karma

lguinn2
Legend

I think you just want

stats count

But I also think that you misunderstand how the Splunk command pipeline works. At each step of the pipeline, the intermediate results are transformed. After you run stats count in the pipeline, the fields app_name and app_id are no longer available to you, as they are no longer included in the intermediate results.

Try this search instead:

index=hig sourcetype="MainframeApps" 
| stats count by app_id app_name
| eventstats sum(count) as total_count
| eval percent = round(count*100/total_count,1)
| rename total_count AS "Total Count" app_id AS "App Code" app_name AS "Application Name" count AS "Number of Events" percent AS "Percent"

lguinn2
Legend

Nice - I forgot about the limit=0 on the top command.

0 Karma

gkanapathy
Splunk Employee
Splunk Employee

or just
index=hig sourcetype=MainframeApps | top limit=0 app_id app_name

Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...