Splunk Search

Is there a way to calculate the percentile of a value within a range of values?

Kenshiro70
Path Finder

One of the most useful functions in Excel is percentilerank, which calculates the percentile of a value within a range of values. The closest I've been able to get is to do a p10, p20, p30, etc. and then search for everything below the value. I'm trying to show benchmarks and the function would be quite useful.

If you're not familiar with the percentilerank function, it works as follows:

  • You specify percentilerank(value, array of values)
  • Percentile rank returns the percentile for that value (e.g., 23rd percentile)

It's basically the converse of the perc commands.

0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

This should be it:

... | stats count by value | sort + value
    | streamstats current=f sum(count) as rank | fillnull rank
    | eventstats sum(count) as total | eval percentile_rank = rank / total * 100

This will assign each unique value its absolute rank and then convert that to percentile rank using the total number of values.

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

This should be it:

... | stats count by value | sort + value
    | streamstats current=f sum(count) as rank | fillnull rank
    | eventstats sum(count) as total | eval percentile_rank = rank / total * 100

This will assign each unique value its absolute rank and then convert that to percentile rank using the total number of values.

Kenshiro70
Path Finder

Nice - it even accounts for duplicate values!

0 Karma

sundareshr
Legend

Have you tried any of these? p<X>(Y) | perc<X>(Y) | exactperc<X>(Y) | upperperc<X>(Y)

http://docs.splunk.com/Documentation/Splunk/6.4.3/SearchReference/CommonStatsFunctions

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...