Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Dax If statement

Hello Looking to see If i can build the following If statemnet below. 

If the Sum of ID Number is < 2 then " $500", 

otherwise if the Sum of ID Number is between 2 and  then "$800"

Otherwise if the sum of ID Number is = > 6 " $1000", "Out of Range"

 

Result should be the Sum of the ID Number is "$1000"

 

 

  • Hi Anonymous ,

     

    I did a test. First, I separated the ID in the power query and got the sum. Then use if judgment on the desktop to find the result. The reference is as follows:

    M_ = 
    IF (
        MAX ( 'Table'[sum_of_id] ) <= 2,
        "$500",
        IF (
            MAX ( 'Table'[sum_of_id] ) < 6
                && MAX ( 'Table'[sum_of_id] ) > 2,
            "$800",
            IF ( MAX ( 'Table'[sum_of_id] ) >= 6, "$1000", "out of range" )
        )
    )


    Best Regards,
    Henry


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

2 Replies

  • Anonymous based on the ID Number shown in the image, you need to extract number from ID which you can easily do in Power Query by using the split from transform tab. Once you have the number separated from the ID, you can use the SWITCH function to achieve your goal.

     

    Follow us on LinkedIn

     

    Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

     

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

  • v-henryk-mstf's avatar
    v-henryk-mstf
    Community Support

    Hi Anonymous ,

     

    I did a test. First, I separated the ID in the power query and got the sum. Then use if judgment on the desktop to find the result. The reference is as follows:

    M_ = 
    IF (
        MAX ( 'Table'[sum_of_id] ) <= 2,
        "$500",
        IF (
            MAX ( 'Table'[sum_of_id] ) < 6
                && MAX ( 'Table'[sum_of_id] ) > 2,
            "$800",
            IF ( MAX ( 'Table'[sum_of_id] ) >= 6, "$1000", "out of range" )
        )
    )


    Best Regards,
    Henry


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