Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

DAX Formula issue

Hi,   I am trying to run the following DAX code. However, it doesn't seem to work.      I am using this nested IF statement, where the first argument is checking a condition, the second argument...
  • Anonymous's avatar
    Anonymous
    7 years ago

    Probably better to use the SWITCH, TRUE() pattern for that many ifs.  Give the following a try and see if that work:

    SWITCH(
    	TRUE(),
    	[MEASURE] > 90, "Greater Than 90 Days",
    	AND([Measure] < 90, [Measure] > 60), "Greater Than 60 Days",
    	AND([Measure] < 60, [Measure] > 30), "Greater Than 30 Days",
    	AND([Measure] < 30, [Measure] > 7), "Greater Than 7 Days",
    	[Measure] <= 7,"Less Than 7 Days",
    	0
    )
    	
  • dedelman_clng's avatar
    dedelman_clng
    7 years ago

    Looks like you may be making it too complicated.  Try using SWITCH() instead and simplify the conditions:

     

    Test Column =
    SWITCH (
        TRUE (),
        DaysSince[Days since Financial Statement] > 90, "Greater than 90 days",
        DaysSince[Days since Financial Statement] > 60, "Greater than 60 days",
        DaysSince[Days since Financial Statement] > 30, "Greater than 30 days",
        DaysSince[Days since Financial Statement] > 7, "Greater than 7 days",
        DaysSince[Days since Financial Statement] <= 7, "Less than 7 days",
        -1
    )

    Since SWITCH() will end evaluation once it hits a true, your code should be able to be simplified as above.  It's possible in all of the nesting, etc you introduced an odd character somewhere in one of the values.

     

    Also note that in the case of getting to the ELSE part of the switch (-1), this will still be a text field, not a number.

     

    Hope this helps

    David