Calculate the Percentage of Total Sales Using DAX?
You can calculate the percentage of total sales by dividing the sales amount of each product by the total sales.
DAX Measure:
% of Total Sales = DIVIDE(SUM(Sales[SalesAmount]), CALCULATE(SUM(Sales[SalesAmount]), ALL(Sales)))
Explanation:
- SUM(Sales[SalesAmount]): Calculates the total sales for the current context (e.g., a product or category).
- CALCULATE(SUM(Sales[SalesAmount]), ALL(Sales)): Calculates the total sales across all products, ignoring any filters applied to the Sales table.
- DIVIDE: Handles division, avoiding errors from dividing by zero.
Example in Action:
If you have the following data, the result should be as below:
ProductName SalesAmount Percentage
Product A $2,000 20%
Product B $3,000 30%
Product C $5,000 50%
This measure dynamically calculates the percentage of total sales for each product and displays it in your Power BI visuals.