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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Danni2
Regular Visitor

Assigning values based on running total and ranking within categories

Hello ,

 

I have a table below and I want to Calculate revenue for each category, rank products based on revenue( within each category) then identify products within each the category that represent 20% with the highest revenue and assign it a value as "A", products that fall in the in the next 30% assign value as B and the rest assign value as C.  I've added a sample table with desired output . Any help would be much appreciated.  Thanks! 

ProductRevenueCategoryDesired output
tea10FoodA
coffee6FoodA
orange5FoodB
pear4FoodB
chips3FoodB
soda2FoodC
coke2FoodC
eggs1.5FoodC
bread1FoodC
sugar0.8FoodC
makeup10OtherA
pants6OtherA
shoes5OtherB
jeans4OtherB
scarf4OtherB
perfume3OtherC
dress2OtherC
skirt2OtherC
suit1OtherC
jacket1OtherC
2 REPLIES 2
v-jialongy-msft
Community Support
Community Support

Hi @Danni2 

 

First, you need to calculate the total revenue for each category.

Total Revenue by Category = 
CALCULATE(
    SUM('Table'[Revenue]),
    ALLEXCEPT('Table', 'Table'[Category])
)

 

Next, rank the products based on their revenue within each category.

Revenue Rank = 
RANKX(
    ALLSELECTED('Table'[Product]),
    CALCULATE(SUM('Table'[Revenue])),
    ,
    DESC,
    Dense
)

 

Now, calculate the percentage for each product within its category.

Percentage = DIVIDE(SELECTEDVALUE('Table'[Revenue]),[Total Revenue by Category])

 

Finally, use the percentage to assign each product to the correct group "A", "B", or "C".

Revenue Category = 
VAR CumPercent = [Percentage]
RETURN
    IF(
        CumPercent <= 0.20, "A",
        IF(
            CumPercent <= 0.50, "B",
            "C"
        )
    )

 

 

 

 

Best Regards,

Jayleny

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-jialongy-msft 

 

Thank you, I tried it but it is not ranking corectly, see below.  Apple should be marked as A and looking at total revenue category output the revenue looks the same for the whole category.  Just to confirm the solution includes 4 measures ? If so how does revenue rank get pulled into the output of other measure ? Thanks

 

33.PNG

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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