Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredJoin us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.
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"
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.