cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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:

 Country area product Brands sales rank UK area1 xyz a1 500.0 7/7 UK area1 xyz a2 200.0 2/7 UK area1 xyz a3 399.0 6/7 UK area1 xyz a4 233.0 3/7 UK area1 xyz a5 134.0 1/7 UK area1 xyz a6 284.0 4/7 UK area1 xyz a7 374.0 5/7 US area1 xyz a8 279.0 2/7 US area1 xyz a9 376.0 5/7 US area1 xyz a10 373.0 4/7 US area1 xyz a11 253.0 1/7 US area1 xyz a12 379.0 6/7 US area1 xyz a13 743.0 7/7 US area1 xyz a14 333.0 3/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.

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

1 ACCEPTED SOLUTION
Community Support

You can try this calculated column.

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

Best Regards,

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

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

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.

Best Regards,

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

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

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

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

 country Product Sales Period Rank x a 200 Q3 2019 1 x b 300 Q4 2018 2 y b 200 Q4 2018 2 z b 200 Q4 2018 2 z a 239 Q3 2018 3 f a 134 Q3 2018 3 g b 143 Q1 2018 4 h c 234 Q1 2018 4

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.

Regards,

Community Support

You can try this calculated column.

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

Best Regards,

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

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

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

It helped me alot 🙂

Super User
Helper III

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.

Super User

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])

))```

Announcements

#### 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.