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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
yousseftb76
Frequent Visitor

current year to date vs. prior year for the same period

Hello,

I have a sales table of 2 years (previous year until today).

Example: today is 01/22/2022 (01 january 2022)

 

I want to filter in power Query the column "DATE_SALE" in such a way to obtain only the sales since:

 

- from January 1 of the Current Year to Today's Day/current month/current year (that is, from 01/01/2022 to 01/22/2022))

- and the same period but last year:

- from January 1 of the Previous Year to Today's Day/current month/Previous Year (that is, from 01/01/2021 to 01/22/2021)

 

I am looking to complete the filter conditions in the DATE_SALE column in Power Query, I suppose it will be something like this:

= Table.SelectRows(#"columna", each [FECHA_VENTA] >= #datetime(Date.Year(DateTime.LocalNow())-1, 1, 1, 0, 0, 0)) and [Date] <= #datetime(Date.Year(DateTime.LocalNow())-1, Date.Month(DateTime.LocalNow()), 1, 0, 0, 0))..................................................

 

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

 

in ACCESS it would be something like this:
Between DateSerial(Year(Date())-1;1;1) AND DateSerial(Year(Date())-1;Month(Date());Day(Date()))
AND
Between DateSerial(Year(Date());1;1) AND Today()

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Please try a filter step with this expression. You can just add a filter step "between" and pick two dates, and then modify it in the Formula Bar to match the below.

 

= Table.SelectRows(#"Inserted Year", each let today = Date.From(DateTime.LocalNow()) in ([Date] >= Date.StartOfYear(Date.AddYears(today, -1)) and [Date] <= Date.AddYears(today, -1)) or (Date.Year([Date]) = Date.Year(today) and [Date] <= today))


Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
mahoneypat
Microsoft Employee
Microsoft Employee

Please try a filter step with this expression. You can just add a filter step "between" and pick two dates, and then modify it in the Formula Bar to match the below.

 

= Table.SelectRows(#"Inserted Year", each let today = Date.From(DateTime.LocalNow()) in ([Date] >= Date.StartOfYear(Date.AddYears(today, -1)) and [Date] <= Date.AddYears(today, -1)) or (Date.Year([Date]) = Date.Year(today) and [Date] <= today))


Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


works correctly.

 

Many many tanks

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Kudoed Authors