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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
axelf24
New Member

Using RANKX within a category

Hello, I am trying to get the correct ranking of values within a category. I attach the details below and would be grateful if you could help here. I have tried several attempts using Google etc but to no avail. Thank you.

axelf24_0-1726148950275.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @axelf24 ,

 

@efebent & @DataNinja777 , thanks for your concern about this case. I tried to create a sample data myself based on @axelf24's requirement and implemented the result. Please check if there is anything that can be improved. Here is my solution:

 

1\My data source-'Table'

vbofengmsft_0-1726639742653.png

2\ Create a measure 

Min Difference Per ID = 
MINX(
    FILTER(
        ALL('table'),
        'table'[ID] = MAX('Table'[ID])
    ),
    'Table'[Dates Difference]
)

3\Result

vbofengmsft_1-1726639795268.png

 

Best Regards,

Bof

 

 

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi @axelf24 ,

 

@efebent & @DataNinja777 , thanks for your concern about this case. I tried to create a sample data myself based on @axelf24's requirement and implemented the result. Please check if there is anything that can be improved. Here is my solution:

 

1\My data source-'Table'

vbofengmsft_0-1726639742653.png

2\ Create a measure 

Min Difference Per ID = 
MINX(
    FILTER(
        ALL('table'),
        'table'[ID] = MAX('Table'[ID])
    ),
    'Table'[Dates Difference]
)

3\Result

vbofengmsft_1-1726639795268.png

 

Best Regards,

Bof

 

 

DataNinja777
Super User
Super User

Hi @axelf24 ,

 

For the case described above, 

1. First adjust the slicer date logic to ensure the correct date range is used.

Slicer Date =
MAXX(
    FILTER(
        ALL('table'),
        [Reference] = MAX([Reference]) &&
        [Processing Date] > MIN('all Date'[Date]) &&
        [Processing Date] <= MAX('all Date'[Date])
    ),
    [Processing Date]
)

Then, rank the differences within each ID and ensure that the ranking is calculated over the correct context. However, you may want to use minx instead of rankx to directly get the minimum value.

Min Difference Per ID =
MINX(
    FILTER(
        ALL('table'),
        'table'[ID] = EARLIER('table'[ID])
    ),
    'table'[Difference]
)

 

Best regards,

Thanks for the quick reply.

Unfortunately when I use the code to create Min Difference Per ID, I get the error message

axelf24_0-1726151639708.png

which I don't quite understand.

Hi @axelf24 ,

 

What about modifying the dax as shown below?

Min Difference Per ID =
CALCULATE(
    MIN('table'[Difference]),
    FILTER(
        'table',
        'table'[ID] = EARLIER('table'[ID])
    )
)

 Best regards,

Still getting error message below (I've just just replaced Table with the actual name and ID with reference):

axelf24_0-1726153316212.png

 

The error you're encountering occurs when a measure tries to operate directly on a column that has multiple rows, making it impossible to return a single value. In this case, the column contains multiple values, so it's giving a warning that a single date value can't be determined.

To fix this issue, you can revise the formula . and use the MAX function to retrieve the highest value in each row

it should be : EARLIER(MAX(.......))

Good morning, thanks for your reply as below.

Sorry to chase but asking if you can suggest any other solutions?

Many thanks for your time.

Many thanks for your reply.

The adjustment suggested still gives the same error - 

 

axelf24_0-1726157947477.png

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors