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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
o59393
Post Prodigy
Post Prodigy

Power Query Date

Hi all

 

I am trying to get the date (YYYY/MM/DD) in power query using an IF statement. 

 

I need to have the year dynamic to today's year. 

 

For example if Attribute column is "Production January (real and/or forecast) then return":

 

Today's Year/1/1 or in other words 2021/1/1

 

I am using the following M code:

 

= Table.AddColumn(#"Filtered Rows1", "Custom", each if [Attribute] = "Production January (real and/or forecast)" then Date.Month(#datetime(Date.Year(DateTime.LocalNow()),1,1))
 else 0)

 

Below is the error:

 

o59393_0-1631226209397.png

 

Thanks.

1 ACCEPTED SOLUTION
HotChilli
Community Champion
Community Champion

Can't read the error (the picture is too small).

Looks like it says error in the cell so just click in the cell - not on the error - and it will display underneath.

--

Having said that, it looks like you are creating a #datetime and you want a #date, so try that

View solution in original post

2 REPLIES 2
HotChilli
Community Champion
Community Champion

Can't read the error (the picture is too small).

Looks like it says error in the cell so just click in the cell - not on the error - and it will display underneath.

--

Having said that, it looks like you are creating a #datetime and you want a #date, so try that

Yes! @HotChilli 

 

Thank you!

Helpful resources

Announcements
Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.