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!

New Year. New Skills. New Course Releases from Splunk Education

A new year often inspires reflection—and reinvention. Whether your goals include strengthening your security ...

Splunk and TLS: It doesn't have to be too hard

Overview Creating a TLS cert for Splunk usage is pretty much standard openssl.  To make life better, use an ...

Faster Insights with AI, Streamlined Cloud-Native Operations, and More New Lantern ...

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