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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
chayanupadhyay
Helper III
Helper III

rank based on grouping of multiple columns

Hi All,

 

I have below data in my table and i need to rank the sales on the basis of country, area.brand and product, PFB the sample data:

 

CountryareaproductBrandssalesrank
UKarea1xyza1500.07/7
UK

area1

xyza2200.02/7
UKarea1xyza3399.06/7
UKarea1xyza4233.03/7
UKarea1xyza5134.01/7
UKarea1xyza6284.04/7
UKarea1xyza7374.05/7
USarea1xyza8279.02/7
USarea1xyza9376.05/7
USarea1xyza10373.04/7
USarea1xyza11253.01/7
USarea1xyza12379.06/7
USarea1xyza13743.07/7
USarea1xyza14333.03/7

 

i have seven different brands which is selling same product in same area in same country, i need to get the above mentioned rank, for an example: Brand a1 to a7 is selling their product in UK in same area and its sales is captured now i need to find the rank of the brand as per their sales amount.

I have multiple countries data in same table with same format as shown  in above sample.

I really appreciate your help on this, thank you in advance.

Please let me know if you need more details on above scenario.

1 ACCEPTED SOLUTION

Hi @chayanupadhyay ,

 

You can try this calculated column.

Column =
RANKX (
    'Table',
    RIGHT ( 'Table'[Period], 4 ) & LEFT ( 'Table'[Period], 2 ),
    ,
    DESC,
    DENSE
)

Capture.PNG

 

Best Regards,

Eads

 

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

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

7 REPLIES 7
v-eachen-msft
Community Support
Community Support

Hi @chayanupadhyay ,

 

You need to add a new calculated column.

Column =
VAR A =
    RANKX (
        CALCULATETABLE (
            test,
            ALLEXCEPT ( test, test[Country], test[area], test[product] )
        ),
        test[sales],
        ,
        ASC,
        DENSE
    )
VAR B =
    COUNTROWS (
        CALCULATETABLE (
            test,
            ALLEXCEPT ( test, test[Country], test[area], test[product] )
        )
    )
RETURN
    A & "/" & B

Here is the result.3-1.PNG

Best Regards,

Eads

 

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

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

Thank you @v-eachen-msft  for your help. It worked .

 

I have to rank Quarter and year as well, PFB the sample data:

countryProductSalesPeriodRank
xa200Q3 20191
xb300Q4 20182
yb200Q4 20182
zb200Q4 20182
za239Q3 20183
fa134Q3 20183
gb143Q1 20184
hc234Q1 20184

 

If you could help me on the DAX statement to get the ranking of Period column, since Q3 2019 is the latest which will rank as 1 and then following quarter with the year will be ranked, if the quarter and year are same then same rank needs to be applied.

 

Period column is text column, Period is coming from source as column and i am unpivoting it and making it as Rows but unable to change its data type to Date and sort it according to that.

 

Thank you in advance for your help.

 

Regards,

Chayan Upadhyay

 

Hi @chayanupadhyay ,

 

You can try this calculated column.

Column =
RANKX (
    'Table',
    RIGHT ( 'Table'[Period], 4 ) & LEFT ( 'Table'[Period], 2 ),
    ,
    DESC,
    DENSE
)

Capture.PNG

 

Best Regards,

Eads

 

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

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

@v-eachen-msftThank you so much for your help and support.

Apologies for replying late.

It helped me alot 🙂

amitchandak
Super User
Super User

Check, if this can help

https://community.powerbi.com/t5/Desktop/Summarize-and-Rank-by-multiple-columns-and-rows/td-p/330108

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Thank you @amitchandak  for sharing the link.

In that use case, they have ranked total sales amount for each combination, in my case i need to rank each brand on their individual sales amount comparing to the other brand sales amount for same country, same area and same product.

 

 

Please check these formulae. These have been created as measures, not columns. If one create them as column they will become aggregatable. There is diff, how you calculate these two

 

RANK Test = VAR x = SUM(Sales[Sales])
RETURN 
	RANKX(
			ALL(Customer[Age Group]),
			CALCULATE(SUM(Sales[Sales])
			
		))
		
RANK Test 1 = VAR x = SUM(Sales[Sales])
RETURN 
	RANKX(
			ALL(Customer[Income Group]),
			CALCULATE(SUM(Sales[Sales])
			
		))
RANK Test 2 = VAR x = SUM(Sales[Sales])
RETURN 
	RANKX(
			ALL(Customer[Age Group],Customer[Income Group]),
			CALCULATE(SUM(Sales[Sales])
			
		))

Screenshot 2019-08-29 21.25.49.png

 

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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