I'm wondering if anyone can help me overcome a little problem I'm experiencing with RANKX in power bi.
I have a table of data with a couple of columns containing duplicate values,
I want to apply a rank number to each value in the table, with the idea of being able to be filter the column on rank "1", which should if my logic is correct, show me all the unique data,
I've added an index column to the table to allow me to rank against,
There are over 5 million rows of data in my table, below is a sample of the data table where I have filtered the HUB_ID on 2 specific duplicate values (just for the purposes of this exercise):
HUB_ID | GUI_ID | SERIAL_NUMBER | Index |
---|---|---|---|
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | Z12N019671 | 669 |
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | Z17QF45418 | 670 |
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | E6S00282861356 | 667 |
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | A381152754 | 665 |
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | BB419120518647 | 666 |
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | E6S02944911660 | 668 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | Z13N030887 | 58427 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | Z17QU39570 | 58428 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | E6S01384441356 | 58425 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | E6S12053371756 | 58426 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | A051339939 | 58423 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | BB216521385155 | 58424 |
the above shows rows with the duplicated data against the HUB_ID, so what I'm looking for is to apply a ranking to the index based on the HUB_ID.
so that I get the following:
HUB_ID | GUI_ID | SERIAL_NUMBER | Index | RANK |
---|---|---|---|---|
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | Z12N019671 | 669 | 5 |
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | Z17QF45418 | 670 | 6 |
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | E6S00282861356 | 667 | 3 |
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | A381152754 | 665 | 1 |
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | BB419120518647 | 666 | 2 |
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | E6S02944911660 | 668 | 4 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | Z13N030887 | 58427 | 5 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | Z17QU39570 | 58428 | 6 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | E6S01384441356 | 58425 | 3 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | E6S12053371756 | 58426 | 4 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | A051339939 | 58423 | 1 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | BB216521385155 | 58424 | 2 |
Apologies that I've not sorted the RANK column into numerical order but hopefully you can understand what I'm attempting to do all the same :o)
The data sits in a table called Macquarie-Database and I have attempted to create a new column with the following:
RANK =
RANKX (
FILTER (
'Macquarie-Database',
'Macquarie-Database'[HUB_ID] = EARLIER ( 'Macquarie-Database'[HUB_ID] )
),
CALCULATE ( MAX ( 'Macquarie-Database'[Index] ) ),
,
ASC,
SKIP
)
However I keep getting the error "A circular dependency was detected: Macquarie-Database[RANK]"
I've used RANKX in exactly same way in other power bi reports which has worked fine, so i'm scratching my head as to why suddenly now I'm getting the error.
Maybe there's a better way to do what I need, I don't know but was hoping that you good people on the forum may be able to help me sort out my rank? :o)
Any help at this initial stage would be greatly appreciated, many thanks in advance
Regards
I have tried:
RANK =
RANKX (
FILTER (
'Macquarie-Database',
'Macquarie-Database'[HUB_ID] = EARLIER ( 'Macquarie-Database'[HUB_ID] )
),
CALCULATE ( MAX ( 'Macquarie-Database'[Index] ) ),
,
ASC,
SKIP
)
However I keep getting the error "A circular dependency was detected: Macquarie-Database[RANK]"
This has worked successfully with previous reports, however for some reason with this latest report I'm getting the error message.
I'm hoping to get a RANK column on the end of my table which ranks (ASCENDING) as per the index value against a HUB_ID:
When this didn't work I then tried:
How to generate rank in Power BI on the basis of two column
RANK_HUB_ID =
RANKX (
ALL ( 'Macquarie-Database' ),
'Macquarie-Database'[HUB_ID],
,
ASC,
DENSE
)
which produced:
HUB_ID | GUI_ID | SERIAL_NUMBER | Index | RANK_HUB_ID |
---|---|---|---|---|
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | Z12N019671 | 669 | 240 |
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | Z17QF45418 | 670 | 240 |
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | E6S00282861356 | 667 | 240 |
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | A381152754 | 665 | 240 |
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | BB419120518647 | 666 | 240 |
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | E6S02944911660 | 668 | 240 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | Z13N030887 | 58427 | 20984 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | Z17QU39570 | 58428 | 20984 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | E6S01384441356 | 58425 | 20984 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | E6S12053371756 | 58426 | 20984 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | A051339939 | 58423 | 20984 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | BB216521385155 | 58424 | 20984 |
and then created a new column with the following:
RANK =
VAR X =
MAX ( 'Macquarie-Database'[RANK_HUB_ID] )
VAR RESULT =
RANKX (
ALL ( 'Macquarie-Database' ),
'Macquarie-Database'[Index] * X + 'Macquarie-Database'[RANK_HUB_ID],
,
ASC
)
RETURN
RESULT
However, this results in the following:
HUB_ID | GUI_ID | SERIAL_NUMBER | Index | RANK_HUB_ID | RANK |
---|---|---|---|---|---|
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | Z12N019671 | 669 | 240 | 669 |
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | Z17QF45418 | 670 | 240 | 670 |
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | E6S00282861356 | 667 | 240 | 667 |
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | A381152754 | 665 | 240 | 665 |
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | BB419120518647 | 666 | 240 | 666 |
NDPD0001564 | F8-E5-CF-00-10-21-B0-2A | E6S02944911660 | 668 | 240 | 668 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | Z13N030887 | 58427 | 20984 | 58427 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | Z17QU39570 | 58428 | 20984 | 58428 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | E6S01384441356 | 58425 | 20984 | 58425 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | E6S12053371756 | 58426 | 20984 | 58426 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | A051339939 | 58423 | 20984 | 58423 |
NDPD0042939 | F8-E5-CF-00-10-0C-1C-98 | BB216521385155 | 58424 | 20984 | 58424 |
So I'm really not sure now where to go with this :o(
Can anyone help please?
Is this what you want? Rank2 = RANKX(FILTER(demo, demo[HUB_ID] = EARLIER(demo[HUB_ID])), demo[Index], , ASC) See results in the photo attached https://i.sstatic.net/Jfc1in52.png