Expression error: The name 'IF' wasn't recognized​. Make sure it's spelled correctly.  Power BI/DAX Functions/Power Query

Karen Schaefer
Karen Schaefer used Ask the Experts™
on
I had this question after viewing Power Query Switch Function vs If statement.

After numerous hours of researching this issue for 2 days, I am really stumped.

I have tried to create a simple function of either If or Switch and both return the above mentioned error.

I even created a sample based on the example supplied on MSDN for the IF Function, trying to use it both in the Power BI Desktop and/or Power Query for Excel 2013 (32 bit) environments. Without any luck.

I am using the latest download of Power query and PBI,  I just set up my computer in the last week.  Urgently need of help.

 Thanks,

Kfs
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ryan ChongSoftware Team Lead

Commented:
what error are you encountered?

>>Keywords are case-sensitive; "if", "then" and "else" must all be lower-case
https://social.technet.microsoft.com/Forums/en-US/62a3e24f-7fc4-472b-a942-9f734c425fa9/if-function-in-custom-column-returns-token-eof-expected?forum=powerquery

would this help?
Karen SchaeferBI ANALYST

Author

Commented:
thanks for the suggestion,  I need to add another layer to this statement to check for Date in a different column(Termed).

if([#"#YearsofService"]>=2) then "2 + Years" else "Less Than 2 Years"

What do I have to include, maybe hasonevalue or Blank()?

if(hasonevalue([Term Date]),"Termed" if([#"#YearsofService"]>=2) then "2 + Years" else "Less Than 2 Years")

Karen
Software Team Lead
Commented:
you may directly compare with " is null "? like this:
if [#"TermDate"] is null or [#"#YearsofService"] is null then "Less Than 2 Years" else  if([#"#YearsofService"]>=2) then "2 + Years" else "Less Than 2 Years"

Open in new window

Karen SchaeferBI ANALYST

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial