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
Anonymous
Not applicable

Use Switch to rank the value but not exactly ?

Hi All,

I have data like below. I use the measure :

Rank Greenery ratio =
VAR _value = [Greenery ratio]
VAR _result =
SWITCH(
    TRUE(),
    _value >=0.3,5,
    _value >=0.25 || _value <0.3,4,
    _value >0.2 || _value <0.25,3,
    _value >0.1 || _value <0.2,2,
    1
)
Return _result
 
Takeshi_yamamo_0-1666171299226.png

The result of 24% and 14% is not true . The rank of 24% is 3 and the rank of 14% is 2. Please help me to fix that measure 

1 ACCEPTED SOLUTION

Hi  @Anonymous,

Please update the formula of measure [Rank Accessbility] as below and check if it can return your expected result... I remove the spaces from the conditions "Within 3km " and "Within 5km ".

Rank Accessbility =
VAR _value =
    SELECTEDVALUE ( Master[CBD_accessibility] )
VAR _result =
    SWITCH (
        TRUE (),
        _value = "Within 3km"5,
        _value = "Within 5km"4,
        _value = "Within 7km", 3,
        _value = "Within 10km", 2,
        _value = "More than 10km", 1
    )
RETURN
    _result

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Thank you so much

johnt75
Super User
Super User

I think you meant to use and in the conditions rather than or

Rank Greenery ratio =
VAR _value = [Greenery ratio]
VAR _result =
    SWITCH (
        TRUE (),
        _value >= 0.3, 5,
        _value >= 0.25
            && _value < 0.3, 4,
        _value > 0.2
            && _value < 0.25, 3,
        _value > 0.1
            && _value < 0.2, 2,
        1
    )
RETURN
    _result
Anonymous
Not applicable

Hi John, thank you so much. I have a measure as : 

 

Rank Accessbility =
var _value = SELECTEDVALUE(Master[CBD_accessibility])
Var _result =
SWITCH(
    TRUE(),
    _value= "Within 3km ",5,
    _value ="Within 5km ",4,
    _value ="Within 7km",3,
    _value ="Within 10km",2,
    _value = "More than 10km",1
)
Return _result
 
But that measure is shown Within 10km , the other is not . I don't know why ? can you help me ?
Takeshi_yamamo_0-1666234851190.png

 

temporarily change the measure to return _value to make sure that SELECTEDVALUE is returning a value correctly. its possible that there is more than 1 value in the filter context. if it is returning a value then make sure that it exactly matches the text you have in the measure, including the number of spaces.

Hi  @Anonymous,

Please update the formula of measure [Rank Accessbility] as below and check if it can return your expected result... I remove the spaces from the conditions "Within 3km " and "Within 5km ".

Rank Accessbility =
VAR _value =
    SELECTEDVALUE ( Master[CBD_accessibility] )
VAR _result =
    SWITCH (
        TRUE (),
        _value = "Within 3km"5,
        _value = "Within 5km"4,
        _value = "Within 7km", 3,
        _value = "Within 10km", 2,
        _value = "More than 10km", 1
    )
RETURN
    _result

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.