Splunk Search

How to show the percentage of unique values

ewanbrown
Path Finder

Hi,

I have a simple search that uses top to get the top 10 countries:

   search ........ | top Country

It will give the top 10 Countries and percentage.

How can I get the same, but look at the top 10 Countries by unique users?

This :

 search ..... | stats dc(ID) as users by  Country | sort users desc limit=10

Will give me the top 10, but not show the % for each.

Is there a way to do this?

Thanks

0 Karma
1 Solution

cmerriman
Super Champion

try this:

 search ..... | eventstats dc(ID) as totalUsers|stats max(totalUsers) as totalUsers dc(ID) as users by  Country | sort users desc limit=10|eval percentage=users/totalUsers*100|fields - totalUsers

View solution in original post

cmerriman
Super Champion

try this:

 search ..... | eventstats dc(ID) as totalUsers|stats max(totalUsers) as totalUsers dc(ID) as users by  Country | sort users desc limit=10|eval percentage=users/totalUsers*100|fields - totalUsers

ewanbrown
Path Finder

Perfect!

Thanks, I knew it was something to do with eventstats, but couldn't get it to work!

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...