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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
OBMBI
Frequent Visitor

Filter based on a related column with RANKX

I am trying to calculate the TopN value for Confidence by Provider name for the latest date.

 

The below works for the ProviderId but the Provider Name is available in a separate table. These are related with an active Cross directional filter, which is set to 'both'.

 

How do I get this to work with the Provider Name? When I put the Provider Name in the legend on my trend chart, it does not recognise the relationship. I've also tried to add the USERELATIONSHIP into the RANKX function but also can't get this to work.

 

TopN Confidence by ProviderId = 
VAR SelectedTop = SELECTEDVALUE('TopN'[TopN])
VAR SelectedOrder = SELECTEDVALUE(FilterOrder[FilterOrder])
VAR RankOrder = IF(FilterOrder = "Top", 1, -1)

RETURN
SWITCH(TRUE(),
    SelectedOrder = "All", [Average Confidence],
    RANKX ( 
            FILTER(
                ALLSELECTED( 
                    'Confidence'[ProviderId], 'Confidence'[Date] 
                    ), 
                    'Confidence'[Date] = MAX(SortByDate[Date])
            ),
            'Confidence'[Average Confidence] * RankOrder
        )
                  <= SelectedTop,
        'Confidence'[Average Confidence]
)

 

6 REPLIES 6
Mohammad_Refaei
Solution Specialist
Solution Specialist

Please try this:

TopN Confidence by ProviderId =
VAR SelectedTop =
    SELECTEDVALUE ( 'TopN'[TopN] )
VAR SelectedOrder =
    SELECTEDVALUE ( FilterOrder[FilterOrder] )
VAR RankOrder =
    IF ( FilterOrder = "Top", 1, -1 )
VAR RankingScope =
    IF ( ISINSCOPE ( ProvidersTable[ProviderName] ), "ProviderName", "ProviderID" )
RETURN
    SWITCH (
        TRUE (),
        SelectedOrder = "All", [Average Confidence],
        IF (
            RankingScope = "ProviderID",
            RANKX (
                FILTER (
                    ALLSELECTED ( 'Confidence'[ProviderId], 'Confidence'[Date] ),
                    'Confidence'[Date] = MAX ( SortByDate[Date] )
                ),
                'Confidence'[Average Confidence] * RankOrder
            ),
            RANKX (
                FILTER (
                    ALLSELECTED ( 'ProvidersTable'[ProviderName], 'Confidence'[Date] ),
                    'Confidence'[Date] = MAX ( SortByDate[Date] )
                ),
                'Confidence'[Average Confidence] * RankOrder
            )
        ) <= SelectedTop, 'Confidence'[Average Confidence]
    )

 

Hopefully it will work.

Hi @Mohammad_Refaei,

 

This does not work as the columns in the second ALLSELECTED are from different tables

All column arguments of the ALL/ALLNOBLANKROW/ALLSELECTED/REMOVEFILTERS function must be from the same table.

 

You are right, I missed the fact that we are using 2 tables.

Why don't you add a calculated column with the related provider name and use it in the same context?

Because this is my fact table.

1. The table is huge a calculated column would impact performance too much

2. The Provider isn't the only thing I need to rank, there are multiple columns in various dimTables, this is just 1 example.

amitchandak
Super User
Super User

@OBMBI , if you create a rank on provider id and use it with provider name in visual, this means rank of provider id insider provider name

 

You need to include provide name in Rank

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak,

Thanks for the reply, I am using the ProviderId in the RANKX and when I use the Provider Name in the visual, all ranks get set to 1.

 

Also, how would you include the Provider Name in the RANKX function? The ALLSELECTED only accepts fields from the same table, but they are in separate tables.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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