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.
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!
Solved! Go to Solution.
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
if Date.Year([Actual Finish]) <= 2021 and Date.Month([Actual Finish]) <= 1 then "1" else "0"
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
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"
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.