Forum Discussion
Correct Power Query Syntax to reflect month and year?
I'm new to Power BI and Power Query and having a hard time finding the correct way to write the syntax for a simple if then statement using month and year. In my if function, one of the parameters I need is today's date to equal a certain month and year.
What I wrote (incorrect):
if Date.From(DateTime.LocalNow()) = Date.From(2021, 02) and ..... then "1" else "0"
Where am I going wrong? Thanks in advance to anyone who helps!
You are close. Use Date.Month and Date.Year for the comparisons.
if Date.Month(a)=Date.Month(b) and Date.Year(a)=Date.Year(b) then x else y
3 Replies
- lbendlinSuper User
You are close. Use Date.Month and Date.Year for the comparisons.
if Date.Month(a)=Date.Month(b) and Date.Year(a)=Date.Year(b) then x else y
- AnonymousNot applicable
Thank you! I think I'm entering the dates wrong. I've looked at the syntax for M Language on Microsoft's site and tried to replicate it, along with trying different formats and it's not working correctly. I also ensured that the Actual Finish Date column is formatted to be Date.Time.
if [Actual Finish] <= Date.Year(2021) and [Actual Finish] <= Date.Month(01) then "1" else "0"
- lbendlinSuper User
if Date.Year([Actual Finish]) <= 2021 and Date.Month([Actual Finish]) <= 1 then "1" else "0"