Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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

I'm using Power Query Editor to create a new column using an if statement. I used the conditional column to create the formula but now I get the below error.  How can I fix this If then statement? See screen shot below.

 

The formula is supposed to look at the column [Loading Date] and if this column is less than today's date than put today's date or else keep the original [Loading Date] value

 

if error.png

 

 

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

@Anonymous ,

 

Modify the formula as below:

= Table.AddColumn(#"Renamed Columns2", "Custom", each if 
[Loading Date] > DateTime.LocalNow() then [Loading Date] else DateTime.LocalNow())

 

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Thanks...I tried changing it to the below but now the rows all show as Error. When I click on the error I get an Expression Error. See below screen shot.

 

Any ideas how to fix?

 

error2.png

@Anonymous ,

 

Modify the formula as below:

= Table.AddColumn(#"Renamed Columns2", "Custom", each if 
[Loading Date] > DateTime.LocalNow() then [Loading Date] else DateTime.LocalNow())

 

Community Support Team _ Jimmy Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Syntax and function is different for M...an example is shown below

 

if [FullDateAlternateKey] = Date.From(DateTime.LocalNow()) then [FullDateAlternateKey] else Date.From(DateTime.LocalNow()))

Greg_Deckler
Super User
Super User

TODAY is a DAX function and therefore invalid M code. You need to use DateTime.LocalNow. Also, drop your parens. M code if statement is:

 

if <condition> then <true> else <false>

 

<condition>, <true> and <false> are placeholders.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.