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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Dynamic RANKX with multiple filters and slicer

Hi,

 

Power BI newbie here. 

I am trying to dynamically rank my dataset for each Sale Transaction based on the Item Price. However i also have a slicer filter for Item Warehouse location which i want to include. I have tried creating the rank column with the below code however run into the  error message : "A TABLE OF MULTIPLE VALUES WAS SUPPLIED WHERE A SINGLE VALUE WAS EXPECTED".

 

RANKX(filter(Sales,earlier(Sales[Sales_Transaction_ID])=Sales[Sales_Transaction_ID]&& allselected(Sales[Item_Warehouse_Location])),Sales[Item_Price],,ASC,dense)

 

 

Any assistance on this would be super appreaciated. Many thanks in advance!

 

Sample dataset:

Sales_Transaction_IDItem_PriceItem_Warehouse_Location
6481.30Melbourne
64813.95Sydney
6489.83Brisbane
6487.84Brisbane
64812.10Adelaide
85423.42Darwin
8544.58Sydney
8546.89Perth
85414.57Melbourne
8542.43Melbourne
1 ACCEPTED SOLUTION

Hi @Anonymous 
Yes it is working but this is a calculated column which cannot interact with the filter context.
Try this measure on the full set of data

Ranking Measure = 
RANKX (
    ALLSELECTED ( Sales ),
    CALCULATE ( SUM ( Sales[Item_Price] ) ),
    ,
    ASC,
    DENSE
)

1.png

View solution in original post

6 REPLIES 6
tamerj1
Super User
Super User

Hi @Anonymous 
Unless you need to use the ranking to slice your data, you can create is as a measure. 

 

Rank Measure =
RANKX ( Sales, SUM ( Sales[Item_Price] ),, ASC, DENSE )

The following calculated column will give ranking per location but does not work for multiple selection. If you select multiple locations it will still calculate the ranking seperately for each location

Ranking Column Per Warehouse =
RANKX (
    CALCULATETABLE (
        Sales,
        ALLEXCEPT ( Sales, Sales[Item_Warehouse_Location] )
    ),
    Sales[Item_Price],
    ,
    ASC,
    DENSE
)

 

Anonymous
Not applicable

Hi @tamerj1 ,

 

Thank you for your quick response.

Yes i will need the rank to be sliced in another visual so a calculated column might be preferred.

I tried your suggested output however its slightly different to what i am after. Sorry, i may not have been clear in the initial post. The rank will be based on the Item Price for each sales transaction and if i filter out a specific location then the rank needs to dynamically recalculate.

My expected 'Rank' column would be as below with all locations selected:

Sales_Transaction_IDItem_Price Item_Warehouse_LocationRank
6481.30Melbourne1
64813.95Sydney5
6489.83Brisbane3
6487.84Brisbane2
64812.10Adelaide4

 

And if i unselected Brisbane on my Item_warehouse_Location then the rank column should present as:

Sales_Transaction_IDItem_Price ( Dollars $)Item_Warehouse_LocationRank
6481.30Melbourne1
64813.95Sydney3
64812.10Adelaide2

 

Hope this is a bit clearer. Thanks for helping out!

@Anonymous 
This dynatic behaviour cannot be achieved by a calculated column. Only measures can be that dynamic. Please check if this measure works and if yes we'll try to find a solution for the ranking slicer

Rank Measure =
CALCULATE (
    RANKX ( Sales, SUM ( Sales[Item_Price] ),, ASC, DENSE ),
    ALLEXCEPT ( Sales, Sales[Sales_Transaction_ID] ),
    VALUES ( Sales[Item_Warehouse_Location] )
)
Anonymous
Not applicable

@tamerj1 
I've implemented this measure and is currently showing all rows as 1. I also have a date slicer on the page (which i might need at a later stage ) and it looks like this ignores the date slicer and looks at the whole dataset.

The initial measure i had below works but need it to also include slicer for Item_warehouse_location:

 

 

Rank =
RANKX (
    FILTER (
        Sales,
        EARLIER ( Sales[Sales_Transaction_ID] ) = Sales[Sales_Transaction_ID]
    ),
    Sales[Item_Price],
    ,
    ASC,
    DENSE
)

 

 

Hi @Anonymous 
Yes it is working but this is a calculated column which cannot interact with the filter context.
Try this measure on the full set of data

Ranking Measure = 
RANKX (
    ALLSELECTED ( Sales ),
    CALCULATE ( SUM ( Sales[Item_Price] ) ),
    ,
    ASC,
    DENSE
)

1.png

I'm trying to achieve this same concept with slicer, but instead of using a calculation, in this example is doing a sum of sales, I need to use the earliest date. How do I achieve this?

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.