Link to home
Create AccountLog in
Avatar of Karen Schaefer
Karen SchaeferFlag for United States of America

asked on

Power Query Switch Function vs If statement

Need help with the correct syntax.  I need to determine based on 3 columns (Year, Years of Service, Terminate)  if the years of service fall between the following criteria or the Termnate column has a date.

   if(["#YearsofService"]=>2,"2+ Years" else "Less than 2 Years") else Terminate(has a date) is not null.  This will be for an new column displaying the criteria text.

also tried Switch function.

=SWITCH(TRUE()
 [#"#YearsofService"] >=2,"2 + Years" & [#"#YearsofService"] <2, "Less Than 2 Years",
 not isblank([Term Date]), "Termed"
 )
ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Karen Schaefer

ASKER

Thanks for your input, however, I am confused.

I tried a switch statement and was unsuccessful:

=SWITCH(TRUE()
  [#"#YearsofService"] >=2,"2 + Years" & [#"#YearsofService"] <2, "Less Than 2 Years",
  not isblank([Term Date]), "Termed"
  )

I need to verify if the Termed field (Date) contains a date if so then return the value of "Termed", else the years of service  > = 2 return the value of "2 + Years"  else,"Less Than 2 Years",

So I need to look at the value of 2 different fields and see if it matches any of the above criteria and return the correct value statement.

K