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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

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
Community Champion
Community Champion

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.



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors