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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
conradcpt
New Member

Filter date column before parsing it to DATEADD

Hi all, 

 

I have a dataset with about 7 years of data. I also have a measure that only shows the sales for the latest year in the dataset. I need to add measures that will show the sales of each prior year to date. So for example, as of today, 2019's data should show from 2019-01-01 to 2019-06-14.

 

I'm using the DATEADD function, but in order for this to work properly, the date column that I parse to it needs to be filtered to this year first, before subtracting a year to show the same timeframe in 2019, otherwise it shows all the prior years. 

 

So my question is, how do I filter a date column before it gets parsed to the DATEADD function?

 

I realize that manually selecting the latest year in a slicer will fix this problem, but the idea is for this to show each year's data correctly without having to select the latest year first. 

 

Thanks!

1 REPLY 1
lbendlin
Super User
Super User

This is commonly referred to as "Year Over Year To Date" or YoYTD

 

For this to work you need to add a calculated column to your Dates table that flags all dates in prior years as either being equal to or

before the current date, or being after the current date.

 

Once you have that flag you incorporate it into the DATEADD formula (or whatever you prefer)

 

Like so:

SalesPYTD = calculate (sum(sales),SAMEPERIODLASTYEAR(dates[date]),flag = TRUE())

 

CAVEAT! (there's always a caveat, innit?)  The weekday structure (and where holidays fall) does not match between years, so you are invariably comparing apples to oranges. Very similar ones, but still apples and oranges.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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