Forum Discussion

kiuhgfkijHFIOuw's avatar
kiuhgfkijHFIOuw
New Member
1 year ago
Solved

PowerBI color mesure does not work

 

ColorMeasure =
SWITCH(
    TRUE(),
    MAX(Rohdaten_E1[Pakete LZ nicht erreicht LZ E2E]) <= 20, "#D3D3D3",
    AND(MAX(Rohdaten_E1[Pakete LZ nicht erreicht LZ E2E]) > 20, MAX(Rohdaten_E1[Pakete LZ nicht erreicht LZ E2E]) <= 50), "#FFDC00",
    "#B40014"
)

 

  • Hi kiuhgfkijHFIOuw 

     

    Could you please explain the issue clearly? What is the visual you are using and what is the error you are getting ?

  • Hi kiuhgfkijHFIOuw 

     

    Welcome to the Microsoft Fabric Community Forum.

    Regarding the issue with your color measure not working as expected in Power BI,while I’m not fully aware of the exact structure of your dataset, I’ve created a sample .pbix file to demonstrate one possible solution


     

    The issue arises from the use of the AND() function inside a SWITCH(TRUE(), ...) statement. In DAX, while AND() returns a Boolean value, its use inside SWITCH(TRUE(), ...) can lead to unexpected behavior, especially when combining multiple conditions that evaluate values from a measure or column.

    To resolve this, update DAX measure as follows: 

    ColorMeasure =
    VAR Value = MAX(Rohdaten_E1[Pakete LZ nicht erreicht LZ E2E])
    RETURN
        SWITCH(
            TRUE(),
            Value <= 20, "#D3D3D3",       
            Value <= 50, "#FFDC00",       
            "#B40014"                     
        )
    


    I have attached a .PBIX, please take a moment to review them and see if this solution aligns with your requirements.

     If this doesn’t fully meet your needs, could you kindly share a sample of your data and more detailed context? That would help us provide a more accurate solution. If you have any additional questions or require further assistance with implementing this measure in your visuals, please do not hesitate to follow up here.

     

    If this response resolves your query, kindly mark it as Accepted Solution to help other community members. A Kudos is also appreciated if you found the response helpful.

     

    Thank you!



     

4 Replies

  • ABD128's avatar
    ABD128
    Resolver II

    Hi kiuhgfkijHFIOuw 

     

    Could you please explain the issue clearly? What is the visual you are using and what is the error you are getting ?

  • v-karpurapud's avatar
    v-karpurapud
    Community Support

    Hi kiuhgfkijHFIOuw 

     

    Welcome to the Microsoft Fabric Community Forum.

    Regarding the issue with your color measure not working as expected in Power BI,while I’m not fully aware of the exact structure of your dataset, I’ve created a sample .pbix file to demonstrate one possible solution


     

    The issue arises from the use of the AND() function inside a SWITCH(TRUE(), ...) statement. In DAX, while AND() returns a Boolean value, its use inside SWITCH(TRUE(), ...) can lead to unexpected behavior, especially when combining multiple conditions that evaluate values from a measure or column.

    To resolve this, update DAX measure as follows: 

    ColorMeasure =
    VAR Value = MAX(Rohdaten_E1[Pakete LZ nicht erreicht LZ E2E])
    RETURN
        SWITCH(
            TRUE(),
            Value <= 20, "#D3D3D3",       
            Value <= 50, "#FFDC00",       
            "#B40014"                     
        )
    


    I have attached a .PBIX, please take a moment to review them and see if this solution aligns with your requirements.

     If this doesn’t fully meet your needs, could you kindly share a sample of your data and more detailed context? That would help us provide a more accurate solution. If you have any additional questions or require further assistance with implementing this measure in your visuals, please do not hesitate to follow up here.

     

    If this response resolves your query, kindly mark it as Accepted Solution to help other community members. A Kudos is also appreciated if you found the response helpful.

     

    Thank you!