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!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...