Forum Discussion

JaweedL's avatar
JaweedL
Helper I
1 year ago
Solved

Nested iF in Dax

Hi all

I am a simple expression to write, yet I am having a lot of trouble to translate in DAX, I must be doing someting consistently wrong. I seek your valuable help. Many thanks.

 

If  [Region]  in ( “NewYork”, “Louisana”)

{

                If [salesAmount] >[Target]

                {

                [value] = 0

                }

}

else    /* Different Region */

{

        If [salesAmount] < [Target]    /* Note check is different < */

                {

                [value]= 0

                }

}

  • Hello JaweedL , 

     

    You can use Switch Function to simplify your If code in DAX, please try the below code..

     

    Result =
    SWITCH (
    TRUE(),
    AND ( OR ( [Region] = "NewYork", [Region] = "Louisana" ), [salesAmount] > [Target] ), 0,
    AND ( NOT ( OR ( [Region] = "NewYork", [Region] = "Louisana" ) ), [salesAmount] < [Target] ), 0,[value])

     

    If you find this helpful , please mark it as solution and Your Kudos/Likes are much appreciated!

     

    Thank You

    Dharmendar S

    LinkedIN 

  • JaweedL 

    what does [value]=0 mean?

     

    maybe you can try something like below

     

    If  ( [Region]  in { “NewYork”, “Louisana”} && salesAmount] >[Target] , XXXX , if ( NOT ([Region]  in { “NewYork”, “Louisana”} ) && [salesAmount] < [Target], XXXX))

4 Replies

  • dharmendars007's avatar
    dharmendars007
    Memorable Member

    Hello JaweedL , 

     

    You can use Switch Function to simplify your If code in DAX, please try the below code..

     

    Result =
    SWITCH (
    TRUE(),
    AND ( OR ( [Region] = "NewYork", [Region] = "Louisana" ), [salesAmount] > [Target] ), 0,
    AND ( NOT ( OR ( [Region] = "NewYork", [Region] = "Louisana" ) ), [salesAmount] < [Target] ), 0,[value])

     

    If you find this helpful , please mark it as solution and Your Kudos/Likes are much appreciated!

     

    Thank You

    Dharmendar S

    LinkedIN 

  • JaweedL 

    what does [value]=0 mean?

     

    maybe you can try something like below

     

    If  ( [Region]  in { “NewYork”, “Louisana”} && salesAmount] >[Target] , XXXX , if ( NOT ([Region]  in { “NewYork”, “Louisana”} ) && [salesAmount] < [Target], XXXX))

    • JaweedL's avatar
      JaweedL
      Helper I

      Hi ryan_mayu

      Thank you. Works perfectly. Value was a meaure that I used for conditiinal formatting

       

  • Thank you Dharmendar. It works, but I have difficulties to understand te code.