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
kasperkc
Frequent Visitor

RANKX not working

Hi 

I have a table of alarms filtered by data, now I would like make a Top N function, where the user can select the "See top N alarms". For this I have be trying to use the RANKX function, but i cannot get it for work proberly. Rank will not be done correltly in relation to the count. Seems that when the function finds and Alarm text that is used for more than one AlarmID, then it will not rank corretly 

 

I would like the function to rank my AlarmID based counts. 

 

Rank N = RANKX(all(Alarms[AlarmID]);[CountRows])
CountRows = COUNT(Alarms[AlarmID])

Here is my filtered data that I am trying to rank

AlarmIDAlarm textCount of AlarmIDCountRowsRank NTop N within selected N
1000Emergency stop activated - 130S52211
1001Power on is not activated - 131S2/131S52211
1002Safety door is not closed - 140K4212111
1003Inlet safety gate is not closed - 146B5 - 145B112211
1004Outlet safety gate is not closed - 146B5 - 146B111111
3086No alarm text specified in HMI3351
3097No alarm text specified in HMI595911
3098No alarm text specified in HMI555521
5000EM01 - Conveyor not initialized9911
5001EM02 - Fixture 1 not initialized9911
5002EM03 - Fixture 2 not initialized9911
5003EM04 - Robot not initialized8811
5004EM05 - Butyl not initialized8811
5020No alarm text specified in HMI111141
5130No alarm text specified in HMI272731

 

1 ACCEPTED SOLUTION
HotChilli
Super User
Super User

This is all to do with context - and it's not straightforward to understand.  I think this is why RANKX causes so much confusion.  I'm pretty sure your Rank measure will work if you remove 'Alarm Text' from the visualisation.

 

When 'Alarm Text' is in the visualisation, it changes the context and you can see that in your example, it works only for rows where the text is the same.

If you ever need to work out what RANKX is doing, investigate RADACAD's concatenatex technique.

 

Short answer : If you want 'Alarm Text' in the visualisation, use

ALL(Alarms) instead of
ALL(Alarms[AlarmID])

View solution in original post

1 REPLY 1
HotChilli
Super User
Super User

This is all to do with context - and it's not straightforward to understand.  I think this is why RANKX causes so much confusion.  I'm pretty sure your Rank measure will work if you remove 'Alarm Text' from the visualisation.

 

When 'Alarm Text' is in the visualisation, it changes the context and you can see that in your example, it works only for rows where the text is the same.

If you ever need to work out what RANKX is doing, investigate RADACAD's concatenatex technique.

 

Short answer : If you want 'Alarm Text' in the visualisation, use

ALL(Alarms) instead of
ALL(Alarms[AlarmID])

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.