Splunk Search

Using stats Min and Max commands inside a search

omend
Path Finder

Hi All,

I have inserted my raw data into Splunk. The data contains many records on sales statistics of different store branches. The data is in a format of "Date" "Branch_ID" "Sales in USD".

I would like to calculate "Score" for each of these records. For simplicity, Lets assume the Score function operates like this - For each record (that stands for one branch sales on a specific date), I would like to normalize the sales number by subtracting the minimal value of this branch sales across history, and divide it by the range of the sales across history (range as the difference between the max and min values).

i.e per record, Score = (Sales - min(All sales values of this branch)) / Range(All sales values of this branch)

Could someone help me with a snippet of this kind of query?

Thanks,
Ori.

Tags (5)
0 Karma
1 Solution

Ayn
Legend

You could probably use eventstats and eval for creating the stats and then performing your calculations.

... | eventstats min(Sales) as minSales, range(Sales) as rangeSales | eval Score = (Sales-minSales)/rangeSales

View solution in original post

Ayn
Legend

You could probably use eventstats and eval for creating the stats and then performing your calculations.

... | eventstats min(Sales) as minSales, range(Sales) as rangeSales | eval Score = (Sales-minSales)/rangeSales

omend
Path Finder

That works perfectly. Thank you very much!

0 Karma
Get Updates on the Splunk Community!

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...

Index This | What goes away as soon as you talk about it?

May 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...

What's New in Splunk Observability Cloud and Splunk AppDynamics - May 2025

This month, we’re delivering several new innovations in Splunk Observability Cloud and Splunk AppDynamics ...