Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

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_In_Scope_Unit_List[Sub Group Sequence E2E] = "1",
"12/01/2018",
IF (
DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] = "2",
"02/01/2019",
IF (
DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] = "3",
"03/01/2019",
IF (
DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] = "4",
"03/01/2019",
IF (
DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] = "5",
"04/01/2019",
IF (
DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] = "6",
"04/01/2019",
IF (
DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] = "7",
"05/01/2019",
IF (
DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] = "8",
"06/01/2019",
IF (
DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] = "9",
"06/01/2019",
IF (
DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] = "10",
"07/01/2019",
IF (
DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] = "11",
"07/01/2019",
IF (
DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] = "12",
"07/01/2019",
IF (
DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] = "13",
"08/01/2019",
IF (
DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] = "14",
"08/01/2019",
IF (
DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] = "15",
"08/01/2019",
IF (
DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] = "16",
"09/01/2019",
IF (
DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] = "17",
"09/01/2019",
IF (
DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] = "18",
"09/01/2019",
IF (
DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] = "19",
"09/01/2019",
IF (
DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] = "20",
"09/01/2019",
IF (
DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] = "21",
"10/01/2019",
IF (
DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] = "22",
"10/01/2019",
IF (
DRIVE_In_Scope_Unit_List[Sub Group Sequence E2E] = "999",
"10/01/2019",
"11/01/2019"
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
)
2 ACCEPTED SOLUTIONS
az38
Community Champion
Community Champion

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


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

View solution in original post

Anonymous
Not applicable

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"
)

 

View solution in original post

4 REPLIES 4
az38
Community Champion
Community Champion

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


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

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"
)

 

az38
Community Champion
Community Champion

@Anonymous 

the correct symbol ";" or ",' is depends on system localization.

Good luck!

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


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
az38
Community Champion
Community Champion

Hi @Anonymous 

if solution is ok, please mark it as solution for future users with the same problem

thanks


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

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

Top Solution Authors
Top Kudoed Authors