Forum Discussion
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
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.
4 Replies
- Greg_Deckler
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.
- AnonymousNot 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()))
- AnonymousNot 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?
- v-yuta-msft
Community Support
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.