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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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.

5 REPLIES 5
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

 

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.