Splunk Search

How to calculate the percentage of the Top 10 products sold over monthly total value per product

iabreu
New Member

Hello everybody,

I need to calculate the total sales value by product over month and calculate the percentage in relation to the total monthly sales value per product:

For exemple:

I have the Top 5 products sold in a month:

Product_Name Total_Sales

Product 1 $100
Product 2 $200
Product 3 $300
Product 4 $400
Product 5 $500

The Total_sold sold was 1500. Now I need to calculate the percentage that Total_Sales is in relation to Total Sold:

Product_Name Total_Sales Percentage
Product 1 $100 13%
Product 2 $200 19%
Product 3 $300 27%
Product 4 $400 33%
Product 5 $500 44%

I used this query to calculate the Total Sales:

sourcetype="vendor_sales"| chart sum(price) as price over product_name

Could you help me?

Thaks All.

Tags (1)
0 Karma
1 Solution

cmerriman
Super Champion

sure! try this:

sourcetype="vendor_sales"|eventstats sum(price) as total_sales |stats sum(price) as sales max(total_sales) as total_sales by product_name|eval Percentage=sales/total_sales*100

if you're only looking for the top 10 products compared to total sales overall, add at the end:

 |sort 0 - sales|head 10

if you want the percentage for the top 10 products and just the total sales for the top 10 products, try this:

sourcetype="vendor_sales" |stats sum(price) as sales by product_name|sort 0 - sales|head 10|eventstats sum(sales) as total_sales|eval Percentage=sales/total_sales*100

View solution in original post

0 Karma

cmerriman
Super Champion

sure! try this:

sourcetype="vendor_sales"|eventstats sum(price) as total_sales |stats sum(price) as sales max(total_sales) as total_sales by product_name|eval Percentage=sales/total_sales*100

if you're only looking for the top 10 products compared to total sales overall, add at the end:

 |sort 0 - sales|head 10

if you want the percentage for the top 10 products and just the total sales for the top 10 products, try this:

sourcetype="vendor_sales" |stats sum(price) as sales by product_name|sort 0 - sales|head 10|eventstats sum(sales) as total_sales|eval Percentage=sales/total_sales*100
0 Karma

iabreu
New Member

Thank you man! Works great!

0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...