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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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 🙂

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

 

 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.