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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

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!

1 ACCEPTED SOLUTION
lbendlin
Super User
Super 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

View solution in original post

3 REPLIES 3
lbendlin
Super User
Super User

if Date.Year([Actual Finish]) <= 2021 and Date.Month([Actual Finish]) <= 1 then "1" else "0"

lbendlin
Super User
Super 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

Anonymous
Not 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"

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors
Users online (10,819)