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
Nnamarie_1997
Frequent Visitor

Ranking measure is not working

Hi, All.

Can you help me with this?

I have this kind of table that consist of location, item, status, score, & target.

 

Nnamarie_1997_1-1654749052005.png

 

  • The first thing I did was to Identified the Scores based on Status using this condition: 

       1Score2: =

       VAR target = CALCULATE(SUMMARIZE('Table','Table'[TARGET]))
       RETURN
       SWITCH(SELECTEDVALUE('Table'[STATUS]),
       "NEGATIVE", CALCULATE(MIN('Table'[SCORE]), 'Table', 'Table'[SCORE] < 0),
       "LOW", CALCULATE(MIN('Table'[SCORE]), 'Table', 'Table'[SCORE] < target),
       "HIGH", CALCULATE(MAX('Table'[SCORE]), 'Table', 'Table'[SCORE] > target),
       "NORMAL", CALCULATE(MAX('Table'[SCORE]))
       )
 
Nnamarie_1997_0-1654751432209.png

 

       And I get this result
 
Nnamarie_1997_2-1654750261242.png

 

  • Now, I want two rank it based on the scores on each status. Using this measure:  

         

    1Rank =
    VAR StatusType = SELECTEDVALUE('Table'[STATUS])
    RETURN
    SWITCH(TRUE(),
    StatusType = "NEGATIVE", RANKX(ALL('Table'[ITEM]),[1Score2:],,ASC, DENSE),
    StatusType= "LOW", RANKX(ALL('Table'[ITEM]),[1Score2:],,ASC, DENSE),
    StatusType = "HIGH", RANKX(ALL('Table'[ITEM]),[1Score2:],,DESC, DENSE),
    StatusType = "NORMAL", RANKX(ALL('Table'[ITEM]),[1Score2:],,DESC, DENSE)
    )
     
    Nnamarie_1997_1-1654751478305.png 
        Then, I get this result
 
Nnamarie_1997_3-1654750669616.png
 
Nnamarie_1997_0-1654750984873.png

 

The measure, works fine for the two country.
But to this country, the rank is not working under Status: Low .
 
Nnamarie_1997_2-1654751119011.png

 

Here is my expected Result:

 

Cases:

If the Status is "NEGATIVE" or "LOW",  the Rank must start in the lowest value.

If the Status is "NORMAL" or HIGH, the Rank must start in the highest value.

 

See Examples Below:

Nnamarie_1997_0-1655254960121.png

Nnamarie_1997_1-1655255010211.png
Nnamarie_1997_2-1655255040301.png

Nnamarie_1997_3-1655255073024.png

 

Thanks in Advance.

 

Please refer to this link for my sample files:

https://drive.google.com/drive/folders/1jDjGSM9fxMoXg3hxIiNIaQQRbBb54Euj

 


 

 
 
 
1 ACCEPTED SOLUTION

Hi, @Nnamarie_1997 

If you need to rank by measure [1Score2: ],please try measure like:

Rank(1Score2) = 
VAR tab =
    ADDCOLUMNS (
        SUMMARIZE (
            FILTER (
                ALLSELECTED ( 'Table' ),
                'Table'[LOCATION] = MAX ( 'Table'[LOCATION] )
                    && 'Table'[STATUS] = MAX ( 'Table'[STATUS] )
            ),
            'Table'[LOCATION],
            'Table'[ITEM],
            'Table'[STATUS]
        ),
        "@1Score2", [1Score2:]
    )
VAR CurrentValue = [1Score2:]
RETURN
    SWITCH (
        TRUE (),
        SELECTEDVALUE ( 'Table'[STATUS] ) IN { "NEGATIVE", "LOW" }, RANKX ( tab, [@1Score2], CurrentValue, ASC, DENSE ),
        SELECTEDVALUE ( 'Table'[STATUS] ) IN { "Normal", "High" }, RANKX ( tab, [@1Score2], CurrentValue, DESC, DENSE )
    )

veasonfmsft_1-1655279007824.png

 

If you need to rank by field Table[SCORE],try measure like:

Rank(score) = 
VAR tab =
    FILTER (
        ALLSELECTED ( 'Table' ),
        'Table'[LOCATION] = MAX ( 'Table'[LOCATION] )
            && 'Table'[STATUS] = MAX ( 'Table'[STATUS] )
    )
RETURN
    SWITCH (
        TRUE (),
        SELECTEDVALUE( 'Table'[STATUS] ) IN { "NEGATIVE", "LOW" }, RANKX ( tab, CALCULATE ( MAX ( 'Table'[SCORE] ) ),, ASC, DENSE ),
        SELECTEDVALUE('Table'[STATUS] ) IN { "Normal", "High" }, RANKX ( tab, CALCULATE ( MAX ( 'Table'[SCORE] ) ),, DESC, DENSE )
    )

 

Best Regards,
Community Support Team _ Eason

View solution in original post

4 REPLIES 4
v-easonf-msft
Community Support
Community Support

Hi, @Nnamarie_1997 

Not quite understand what you mean. From your formula, the value of rank should depend on the value of [1Score2:].

What is your expected result?

 

Best Regards,
Community Support Team _ Eason

 

Hi @v-easonf-msft ,

Sorry for Late Reply.

 Here is my expected result.

 

Cases:

If the Status is "NEGATIVE" or "LOW",  the Rank must start in the lowest value.

If the Status is "NORMAL" or HIGH, the Rank must start in the highest value.

 

See Examples Below:

Nnamarie_1997_0-1655255576983.png

 

Nnamarie_1997_1-1655255577184.png

 

 

Nnamarie_1997_2-1655255577164.png

 

Nnamarie_1997_3-1655255576872.png

 

Thank You..

Hi, @Nnamarie_1997 

If you need to rank by measure [1Score2: ],please try measure like:

Rank(1Score2) = 
VAR tab =
    ADDCOLUMNS (
        SUMMARIZE (
            FILTER (
                ALLSELECTED ( 'Table' ),
                'Table'[LOCATION] = MAX ( 'Table'[LOCATION] )
                    && 'Table'[STATUS] = MAX ( 'Table'[STATUS] )
            ),
            'Table'[LOCATION],
            'Table'[ITEM],
            'Table'[STATUS]
        ),
        "@1Score2", [1Score2:]
    )
VAR CurrentValue = [1Score2:]
RETURN
    SWITCH (
        TRUE (),
        SELECTEDVALUE ( 'Table'[STATUS] ) IN { "NEGATIVE", "LOW" }, RANKX ( tab, [@1Score2], CurrentValue, ASC, DENSE ),
        SELECTEDVALUE ( 'Table'[STATUS] ) IN { "Normal", "High" }, RANKX ( tab, [@1Score2], CurrentValue, DESC, DENSE )
    )

veasonfmsft_1-1655279007824.png

 

If you need to rank by field Table[SCORE],try measure like:

Rank(score) = 
VAR tab =
    FILTER (
        ALLSELECTED ( 'Table' ),
        'Table'[LOCATION] = MAX ( 'Table'[LOCATION] )
            && 'Table'[STATUS] = MAX ( 'Table'[STATUS] )
    )
RETURN
    SWITCH (
        TRUE (),
        SELECTEDVALUE( 'Table'[STATUS] ) IN { "NEGATIVE", "LOW" }, RANKX ( tab, CALCULATE ( MAX ( 'Table'[SCORE] ) ),, ASC, DENSE ),
        SELECTEDVALUE('Table'[STATUS] ) IN { "Normal", "High" }, RANKX ( tab, CALCULATE ( MAX ( 'Table'[SCORE] ) ),, DESC, DENSE )
    )

 

Best Regards,
Community Support Team _ Eason

Hi @v-easonf-msft,

It means a lot.

Thank you so much for your help.

 

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.

Top Solution Authors