Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Is there any other way to do a If Statement? or Simplify the code

I am create a new column to do an If statement. I did use DAX Formatter to use it. The code is working. But i am wondering is there any better way to do it.    Sub Group Seq Date = IF ( DRIVE_I...
  • az38's avatar
    6 years ago

    Hi Anonymous 

    Its not a Power Query, its a DAX question, as I see

    Anyway, try Switch function https://docs.microsoft.com/en-us/dax/switch-function-dax like

     

    Sub Group Seq Date = 
    SWITCH(
    DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] ;
    "1";"12/01/2018";
    "2";"02/01/2019";
    "3";"03/01/2019";
    "Unknown number"
    )

     

    do not hesitate to give a kudo to useful posts and mark solutions as solution

    LinkedIn

  • Anonymous's avatar
    Anonymous
    6 years ago

    Thank you az38. You code is almost right need to replace ";" to "," and then i can run it. 

     

    Sub Group Seq Date =
    SWITCH (
        DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E],
        "1", "12/01/2018",
        "2", "02/01/2019",
        "3", "03/01/2019",
        "4", "03/01/2019",
        "5", "04/01/2019",
        "6", "04/01/2019",
        "7", "05/01/2019",
        "8", "06/01/2019",
        "9", "06/01/2019",
        "10", "07/01/2019",
        "11", "07/01/2019",
        "12", "07/01/2019",
        "13", "08/01/2019",
        "14", "08/01/2019",
        "15", "08/01/2019",
        "16", "09/01/2019",
        "17", "09/01/2019",
        "18", "09/01/2019",
        "19", "09/01/2019",
        "20", "09/01/2019",
        "21", "10/01/2019",
        "22", "10/01/2019",
        "999", "10/01/2019",
        "11/01/2019"
    )