cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper IV
Helper IV

Expression error: The name 'IF' wasn't recognized. Make sure it's spelled correctly.

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

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User III
Super User III

Re: Expression error: The name 'IF' wasn't recognized. Make sure it's spelled correctly.

Hi Karen,

sorry, didn't read your question right. This will be the formula with the added condition:

 

if [TermDate] <> null then ''Termed" else if ([#"#YearsofService"]>=2) then "2 + Years" else "Less Than 2 Years")

 

or

 

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

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

11 REPLIES 11
Highlighted
Community Champion
Community Champion

Re: Expression error: The name 'IF' wasn't recognized. Make sure it's spelled correctly.

Post a screenshot...

Highlighted
Helper IV
Helper IV

Re: Expression error: The name 'IF' wasn't recognized. Make sure it's spelled correctly.

Capture.PNG

Highlighted
Community Champion
Community Champion

Re: Expression error: The name 'IF' wasn't recognized. Make sure it's spelled correctly.

@kfschaefer this is an issue with M

 

to me it looks like you are mixing up DAX and M the way you reference the column???

 

But @ImkeF is the M expert - maybe she can help you???

Highlighted
Community Champion
Community Champion

Re: Expression error: The name 'IF' wasn't recognized. Make sure it's spelled correctly.

I think in M you have to use => if .... then ... else...

Highlighted
Super User III
Super User III

Re: Expression error: The name 'IF' wasn't recognized. Make sure it's spelled correctly.

Exactly as @Sean said. And watch out: M is case sensitive!

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Highlighted
Continued Contributor
Continued Contributor

Re: Expression error: The name 'IF' wasn't recognized. Make sure it's spelled correctly.

Hi @kfschaefer,

 

   is as @Sean and @ImkeF said. Take a look at this examples:

 

Excelguru

Technet

 

Just remember as @ImkeF said that M is very case sensitive so you have to write:   if (. . .) then (. . .) else (. . .)

 

 

#I'M Not An Expert#

Highlighted
Helper IV
Helper IV

Re: Expression error: The name 'IF' wasn't recognized. Make sure it's spelled correctly.

How should I modify the if then else statement to include another layer:

 

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

 

Could you help with the syntax?

 

Karen

Highlighted
Super User III
Super User III

Re: Expression error: The name 'IF' wasn't recognized. Make sure it's spelled correctly.

try this:

 

= Table.AddColumn(#"Reordered Columns2", "YearsofSvce", each if [YrofSvc] < 2 then 1 else 2)

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Highlighted
Super User III
Super User III

Re: Expression error: The name 'IF' wasn't recognized. Make sure it's spelled correctly.

Hi Karen,

sorry, didn't read your question right. This will be the formula with the added condition:

 

if [TermDate] <> null then ''Termed" else if ([#"#YearsofService"]>=2) then "2 + Years" else "Less Than 2 Years")

 

or

 

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

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

July 2020 Community Highlights

July 2020 Community Highlights

Learn about the exciting things that happened in July.

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

We are thrilled to announce we will begin running a monthly webinar series named Power BI Dev Camp.

Power BI Desktop August 2020 Update

Power BI Desktop August 2020 Update

We have great updates this month! Click the link for the video with more info.

Top Solution Authors
Top Kudoed Authors