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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
PowerBI-Newbie
Helper IV
Helper IV

Dynamic Rank 1st, 2nd and 3rd Filtering Based on Slicer Selection

I have the following graph on 3 separate pages of a Power BI report showing the breakdown of a category and sub-category:

PowerBINewbie_0-1721298221676.png

 

The idea is that each page will represent a location (dynamic) based on the user's date selection:

  • Location 1 - Highest count (from measure 1)
  • Location 2 - 2nd highest count (from measure 1)
  • Location 3 - 3rd highest count (from measure 1)

So locations 1, 2 and 3 will dynamically change based on the user's date selection. In the event that two or more locations have the same value then the alphabetical order is taken into, see table below:

 

PowerBINewbie_2-1721300526108.png

 

So what I need is someway of applying the Rank Measure to the graph above - rank 1 for highest, rank 2 for 2nd highest, rank 3 for 3rd highest. The measures that I have for the count are as follows:

Count Measure:

Count Measure = CALCULATE(COUNT(Issues[Date]),Issues[Not Cancelled] = 1)+0

 

Rank Measure (I got this from another post in the Community Forum and adapted it for my use case):

Rank Measure = 

VAR _table =
    ADDCOLUMNS (
        ADDCOLUMNS (
            ALL ( Issues Location[Location] ),
            "@rankone", CALCULATE ( RANKX ( ALL ( Issues Location[Location] ), [Count Measure],, DESC ) ),
            "@ranktwo",
                CALCULATE (
                    RANKX (
                        ALL ( Issues Location[Location] ),
                        CALCULATE ( MAX ( Issues Location[Location] ) ),
                        ,
                        ASC
                    )
                )
        ),
        "@newindex",
            [@rankone] * 100 + [@ranktwo]
    )
 
VAR _newtable =
    ADDCOLUMNS ( _table, "@newrank", RANKX ( _table, [@newindex],, ASC ) )
RETURN
    IF (
        HASONEVALUE ( Issues Location[Location] ),
        MAXX (
            FILTER ( _newtable, Issues Location[Location] = MAX ( Issues Location[Location] ) ),
            [@newrank]
        )
    )

 

I don't know where to apply the Rank Measure so that I can filter the respective graphs on each of those pages. Any help is greatly appreciated.

6 REPLIES 6
amitchandak
Super User
Super User

@PowerBI-Newbie , Use index function. You can use Parameter and measure to make it dynamic

 

 

example

 

Top1 =

calculate([%scrap], KEEPFILTERS(index(1, All(SAPWorkCenter[CDL]), orderby([%scrap],desc) ) ))

 

Top 2=

calculate([%scrap], KEEPFILTERS(index(2, All(SAPWorkCenter[CDL]), orderby([%scrap],desc) ) ))

 

 

Top N=

calculate([%scrap], KEEPFILTERS(index([selected Parameter], All(SAPWorkCenter[CDL]), orderby([%scrap],desc) ) ))

 

Power BI Index function: Top/Bottom Performer by name and value- https://youtu.be/HPhzzCwe10U

 

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak ,

Thank you very much for your response. It's gotten me half-way there after adapting it for my need.

I have the following measure:

2nd Highest Location = 
VAR _2ndValue = INDEX(2,SUMMARIZE(ALLSELECTED(Issues[Location]),Issues[Location], "_count not cancelled",[Count Not Cancelled]),ORDERBY([Count Not Cancelled],DESC))
RETURN
MAXX(_2ndValue,[Location])

 

This provides me with the name of the location with the 2nd highest value which is excellent and so I wanted to use it in the following measure for the y-axis so that the categories and sub-categories can be filtered based on 2nd highest location:

 

Count - Not Cancelled 2nd = 
CALCULATE(COUNT(Issues[Incident Date]),
Issues[Count If not cancelled] = 1,
Issues[Location] = [2nd Highest Location])+0

But this gives me PLACEHOLDER error and so I tried using variables but it doesn't filter the data properly. However, when I hardcode the value like the following it works perfectly:

 Issues[Location] = "Location 2"

 

I don't know what the issue is.

@PowerBI-Newbie , if this from a connected table, measure can be filtered using a code like

calculate([%scrap], KEEPFILTERS(index(2, All(SAPWorkCenter[CDL]), orderby([%scrap],desc) ) ))

 

but if you first want to get value and pass it on to another table

 

calculate([Meausre], filter(Table, Table [Location] = [2nd Highest location]))

 

if you will use +0, it will show all other location with blank values

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak

Where do I use +0? And where do I put this measure?

Hi @amitchandak,

Any assistance is greatly appreciated.

Hi @amitchandak,

I hope you're well.

I don't want to create a new question so would greatly appreciate your help with the above query.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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