Splunk Search

Percentage based on Grand Total

andrehl
Explorer

index="stage"
|stats dc(customers_name) as "Distinct Customer" by sku_name sku_number
|rename sku_name as Product sku_number as ID
|eval Rate=""Distinct Customer" / count(customers_name)"."%"

Hi guys,
I'm trying to calculate the percentage of the customer involved with respect to the grand total number of customers but I cant seem to use count under eval. Any help?

Thank you!

0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

count is a stats function, not an eval function. You need to calculate count(customers_name) in a separate command.

index="stage"
| eventstats count(customers_name) as customerCount dc(customers_name) as "Distinct Customer" by sku_name sku_number
|rename sku_name as Product sku_number as ID
|eval Rate=('Distinct Customer' / customerCount)."%"
---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust

count is a stats function, not an eval function. You need to calculate count(customers_name) in a separate command.

index="stage"
| eventstats count(customers_name) as customerCount dc(customers_name) as "Distinct Customer" by sku_name sku_number
|rename sku_name as Product sku_number as ID
|eval Rate=('Distinct Customer' / customerCount)."%"
---
If this reply helps you, Karma would be appreciated.
0 Karma

andrehl
Explorer

Is it still possible to sort if we have characters under eval command?

0 Karma

niketn
Legend

@andrehl, which version of Splunk are you on? Also what is the visualization to depict above output? Is it table or something else?

If you are on Splunk 6.5 or higher you can use Table format option to add Unit as % rather than adding % in the eval SPL command. This way your data remains numeric and still displays % in the column.

Refer to Splunk Documentation: https://docs.splunk.com/Documentation/Splunk/latest/Viz/TableFormatsXML#Number_format_rules

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
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!

SOK it to Me: Top 3 Benefits of Using Splunk Operator on Kubernetes that’ll Make ...

    Thursday, July 9, 2026  |  11:00AM–12:00PM PDT Duration: 1 hour (includes Q&A) Managing can feel like a ...

Upgrade Prep for 10.4, Network Observability Deep Dives, and More from Splunk Lantern

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...

Splunk Developer Day announcements: AI agents, MCP tools, Forecasting, and Custom ...

Splunk Developer Day was packed with product and platform updates for developers building in the AI ...