cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
lbnguyn Frequent Visitor
Frequent Visitor

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

Accepted Solutions
az38 Super Contributor
Super Contributor

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

Hi @lbnguyn 

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

View solution in original post

lbnguyn Frequent Visitor
Frequent Visitor

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

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 Super Contributor
Super Contributor

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

Hi @lbnguyn 

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

View solution in original post

az38 Super Contributor
Super Contributor

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

Hi @lbnguyn 

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

thanks

lbnguyn Frequent Visitor
Frequent Visitor

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

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

az38 Super Contributor
Super Contributor

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

@lbnguyn 

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

Helpful resources

Announcements
New Topics Started Badges Coming

New Topics Started Badges Coming

We're releasing new versions of the badge that everyone's talking about. ;) Check your inbox for notifications.

MBAS 2020

Save the new date (and location)!

Our business applications community is growing—so we needed a different venue, resulting in a new date and location. See you there!

Difinity Conference

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)