Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
TessSA
Regular Visitor

DAX: Divide product by selected category

Hello!

 

I have three product SKU categories (A, B, C) and would like to divide the total sales of each of categories A and B by one selected category (C). I have created the following measure in DAX:

 

% Sales on C =
var _category = SELECTEDVALUE('Won Quotes w  Line Items from 2023 - PBI'[SKU Category])
var _value = SELECTEDVALUE('Won Quotes w  Line Items from 2023 - PBI'[Quote Line Item: Total Price (converted).amount])
var _total = [Total C Sales]
var _result = DIVIDE(_value,_total,"")
return _result

 

It is calculating the sales of A, B and C categories divided by C. Is there a way to exclude C category from being calculated in the result? It's always going to show 100%... 

 

See attached screenshot:

Captura de pantalla 2024-11-15 114849.png

1 ACCEPTED SOLUTION
rohit1991
Super User
Super User

Here a few steps in oder to solve your problem. hope this helps:

  1. Current Measure Logic:

    • The current measure is dividing the sales of each category (A, B, and C) by the sales of category C.
    • As you mentioned, category C always shows 100%, which is expected because it's dividing the sales of category C by itself.
  2. Excluding Category C:

    • The issue arises because the calculation doesn’t differentiate category C from the other categories.
    • You need to add a filter condition that excludes category C when calculating the percentage for categories A and B.
  3. Solution Approach:

    • Use a Filter Condition: Modify the measure to apply a filter that only calculates the division for categories A and B, but not for C.
    • Conditional Calculation: You can include a condition to check if the selected category is not "C" and proceed with the calculation only for A and B.
  4. Potential Solutions:

    • IF Statement: Use an IF statement to check if the category is C, and if so, return a blank or another result instead of performing the division.
    • FILTER Function: Apply the FILTER function to exclude the C category in your calculations.
  5. Outcome:

    • This should result in a correct percentage calculation for categories A and B relative to category C, while category C does not perform a calculation of 100%.

In short, modify the measure logic to exclude category C during the calculation, ensuring it does not impact the result.

% Sales on C =
var _category = SELECTEDVALUE('Won Quotes w Line Items from 2023 - PBI'[SKU Category])
var _value = SELECTEDVALUE('Won Quotes w Line Items from 2023 - PBI'[Quote Line Item: Total Price (converted).amount])
var _total = [Total C Sales]

-- Check if the selected category is not "C" and perform the division only for A and B
var _result = IF(_category <> "C", DIVIDE(_value, _total, ""), BLANK())

return _result

View solution in original post

2 REPLIES 2
TessSA
Regular Visitor

Thank you very much, that worked like a charm!

rohit1991
Super User
Super User

Here a few steps in oder to solve your problem. hope this helps:

  1. Current Measure Logic:

    • The current measure is dividing the sales of each category (A, B, and C) by the sales of category C.
    • As you mentioned, category C always shows 100%, which is expected because it's dividing the sales of category C by itself.
  2. Excluding Category C:

    • The issue arises because the calculation doesn’t differentiate category C from the other categories.
    • You need to add a filter condition that excludes category C when calculating the percentage for categories A and B.
  3. Solution Approach:

    • Use a Filter Condition: Modify the measure to apply a filter that only calculates the division for categories A and B, but not for C.
    • Conditional Calculation: You can include a condition to check if the selected category is not "C" and proceed with the calculation only for A and B.
  4. Potential Solutions:

    • IF Statement: Use an IF statement to check if the category is C, and if so, return a blank or another result instead of performing the division.
    • FILTER Function: Apply the FILTER function to exclude the C category in your calculations.
  5. Outcome:

    • This should result in a correct percentage calculation for categories A and B relative to category C, while category C does not perform a calculation of 100%.

In short, modify the measure logic to exclude category C during the calculation, ensuring it does not impact the result.

% Sales on C =
var _category = SELECTEDVALUE('Won Quotes w Line Items from 2023 - PBI'[SKU Category])
var _value = SELECTEDVALUE('Won Quotes w Line Items from 2023 - PBI'[Quote Line Item: Total Price (converted).amount])
var _total = [Total C Sales]

-- Check if the selected category is not "C" and perform the division only for A and B
var _result = IF(_category <> "C", DIVIDE(_value, _total, ""), BLANK())

return _result

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.