Link to home
Start Free TrialLog 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
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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