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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Rankx Skipping a number in Dynamic Rank Measure with What-If Analysis

The goal is to dynamically rank employees based on average performance, where date, program, employee name and %contribution (as a what-if analysis scenario measure) is used.

 

Rank Code: 

'Dim.Employee'[Employeefullname] is used to filter multiple visuals at the same time, hence the crossjoin.

 

 

 

Performance Rank = 
    IF(
        HASONEVALUE('dim Employee'[EmployeeFullName]),
        RANKX(
            CROSSJOIN(
                ALL('dim Employee'[EmployeeFullName]), 
                ALL( 'fact Work Order Details'[EmployeeFullName] )
                ), 
            [Average Performance],,DESC, Dense), 
        "-"
    )

 

 

 

 

Average Performance Measure Code (where level closed is the %contribution set by the what if analysis slicer):

 

 

 

Average Performance = 
    CALCULATE(
        AVERAGEX('fact Work Order Details','fact Work Order Details'[Performance]), 
        FILTER('fact Work Order Details', 'fact Work Order Details'[PercentWork] >= 'Level Closed'[Level Value])
        )

 

 

 

 

However, on some values, when a single employee is selected, it skips a number. The current Rank below should be 11, but it is giving 12. I also have an audit table. Where it ranks properly in the table but gives 12 in the total. Not sure what is going on there. It does not do this for all the other employee selections.

 

Faulty Result: 

Bar Rank.PNGTable Rank.PNG

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , first of all the dimesion should join to the fact names and only dimension should be use .

 

You should try like

 

 

RANKX(
            CROSSJOIN(
                ALL('dim Employee'[EmployeeFullName]), 
                ), 
            [Average Performance],,DESC, Dense)

 

 

If the tables are joined then

 

 

RANKX(
            summarize(all('fact Work Order Details')
                ('dim Employee'[EmployeeFullName]), 
                ( 'fact Work Order Details'[EmployeeFullName] )
                ), 
            [Average Performance],,DESC, Dense)

 

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , first of all the dimesion should join to the fact names and only dimension should be use .

 

You should try like

 

 

RANKX(
            CROSSJOIN(
                ALL('dim Employee'[EmployeeFullName]), 
                ), 
            [Average Performance],,DESC, Dense)

 

 

If the tables are joined then

 

 

RANKX(
            summarize(all('fact Work Order Details')
                ('dim Employee'[EmployeeFullName]), 
                ( 'fact Work Order Details'[EmployeeFullName] )
                ), 
            [Average Performance],,DESC, Dense)

 

Anonymous
Not applicable

Thanks Amit! 

 

I updated the Rankx statement to use only the dim column but that didn't fix the issue. 

 

I decided to iterate through the different inputs and finally found what the issue was. I had put the table filter outside of the AverageX function. Not sure what was wrong but the rankx function didn't like that. 

 

I update the scripts to this, and it works perfectly now. Your recommendation did clean up the query though. Thanks!

 

Calculation Measure:

Average Performance = 
    CALCULATE(
        AVERAGEX(
            FILTER('fact Work Order Details', 'fact Work Order Details'[PercentWork] >= 'Level Closed'[Level Value]),
            'fact Work Order Details'[Performance])
        )

 

Rankx Measure:

Performance Rank = 
    IF(
        HASONEVALUE('dim Employee'[EmployeeFullName]),
        RANKX(
                ALL('dim Employee'[EmployeeFullName]), 
            [Average Performance],,DESC, Skip), 
        "-"
    )

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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