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!

Combine Multiline Logs into a Single Event with SOCK - a Guide for Advanced Users

This article is the continuation of the “Combine multiline logs into a single event with SOCK - a step-by-step ...

Everything Community at .conf24!

You may have seen mention of the .conf Community Zone 'round these parts and found yourself wondering what ...

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...