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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Qotsa
Helper V
Helper V

Rank by hierarchy in a mtrix table

Hi,

 

Need to rank 'Location' which is the 2nd hierarchy. 1st hierarchy is 'Group CHO1' which ranks correctly.

 

This is what I have and it ranks the 1st hierarchy correctly but not the 2nd is all 1.

 

Ranks By Hierarchy = IF (
ISFILTERED (Query1[Group CHO1]),
rankx(all(Query1[Group CHO1]),[Last 8 by Con])
, IF(
ISFILTERED (Query1[Location]),
rankx(all(Query1[Location]),[Last 8 by Con])))
 
Qotsa_0-1620849502080.png

 

3 ACCEPTED SOLUTIONS
Ashish_Mathur
Super User
Super User

Hi,

Does this measure work?

Ranks By Hierarchy = IF(HASONEVALUE(Query1[Location]),rankx(all(Query1[Location]),[Last 8 by Con]),rankx(all(Query1[Group CHO1]),[Last 8 by Con]))

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

Jihwan_Kim
Super User
Super User

Hi, @Qotsa 

Please check the below picture and the measure.

I tried to create a sample similar to the case.

I am not sure how your whole data model looks like, but I suggest "defining the lower level hierarchy's rank first" in the measure is critical.

 

Picture3.png

 

Rank by Hierarchy =
SWITCH (
TRUE (),
ISINSCOPE ( 'Table'[Product] ), RANKX ( ALL ( 'Table'[Product] ), [Qty total] ),
RANKX ( ALL ( 'Table'[Group] ), [Qty total] )
)
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

@Jihwan_Kim Your measure works. Grouping thelower level first is key it seems.

Thank you. 

View solution in original post

5 REPLIES 5
Jihwan_Kim
Super User
Super User

Hi, @Qotsa 

Please check the below picture and the measure.

I tried to create a sample similar to the case.

I am not sure how your whole data model looks like, but I suggest "defining the lower level hierarchy's rank first" in the measure is critical.

 

Picture3.png

 

Rank by Hierarchy =
SWITCH (
TRUE (),
ISINSCOPE ( 'Table'[Product] ), RANKX ( ALL ( 'Table'[Product] ), [Qty total] ),
RANKX ( ALL ( 'Table'[Group] ), [Qty total] )
)
 

Hi, My name is Jihwan Kim.


If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.


Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


@Jihwan_Kim Your measure works. Grouping thelower level first is key it seems.

Thank you. 

Ashish_Mathur
Super User
Super User

Hi,

Does this measure work?

Ranks By Hierarchy = IF(HASONEVALUE(Query1[Location]),rankx(all(Query1[Location]),[Last 8 by Con]),rankx(all(Query1[Group CHO1]),[Last 8 by Con]))

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur Your measure works. Grouping by the lower level first it seems is the way to do it.

Thank you.

You are welcome.  If my reply helped, please mark it as Answer.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.