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! Request now

Reply
Syndicate_Admin
Administrator
Administrator

power query: current year to date versus previous year for the same period

Hello

I have a 2 year sales table (previous year to this day).

Example: today is 22/01/2022

I want to filter in power Query the column "FECHA_VENTA" in such a way to get only the sales from:

- from January 1 of the Current Year to Diadehoy/mesactual/current year (that is, from 01/01/2022 to 22/01/2022))

- and the same period but last year:

- from January 1 of the YearAnterior to Diadehoy/mesactual/añoaPrevious (that is, from 01/01/2021 to 22/01/2021)

you can please help me to correctly put these conditions in the date filter

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Syndicate_Admin ,

 

Here I suggest you to create a custom column by M code and then filter your table by this column. DateTime.LocalNow can help you get today's datetime, it is dynamic.

M Code:

Custom Filter
=
if 
(
Date.Year ([FECHA_VENTA])= Date.Year ( DateTime.LocalNow()) 
or

Date.Year ([FECHA_VENTA]) = Date.Year ( DateTime.LocalNow()) -1 
)

and 

Date.Month([FECHA_VENTA]) <= Date.Month (DateTime.LocalNow()) 

and

Date.Day([FECHA_VENTA]) <= Date.Day (DateTime.LocalNow()) 

then "Ture"

else "False"

Then select "True" in [Custom Filter] column.

1.png

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Syndicate_Admin ,

 

Here I suggest you to create a custom column by M code and then filter your table by this column. DateTime.LocalNow can help you get today's datetime, it is dynamic.

M Code:

Custom Filter
=
if 
(
Date.Year ([FECHA_VENTA])= Date.Year ( DateTime.LocalNow()) 
or

Date.Year ([FECHA_VENTA]) = Date.Year ( DateTime.LocalNow()) -1 
)

and 

Date.Month([FECHA_VENTA]) <= Date.Month (DateTime.LocalNow()) 

and

Date.Day([FECHA_VENTA]) <= Date.Day (DateTime.LocalNow()) 

then "Ture"

else "False"

Then select "True" in [Custom Filter] column.

1.png

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

vanessafvg
Super User
Super User

I am not sure you can do this in power query.   Can you just bring back the last 2 years data and then  manage  the last year and this year combinations using dax in your measures?

 

you could probably create a function to do this but i think it would be a custom function.  





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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 Solution Authors
Top Kudoed Authors