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
user5341567
Helper I
Helper I

Calculate Sales for Same Day of the Week LY

Hello,

 

I am trying to calculate sales LY that would be equal to the same day of the week LY (i.e., 2/1/2025 vs. 2/3/2024). 

 

Most solutions I am finding are using SAMEPERIODLASTYEAR, which compares 2/1/2025 vs. 2/1/2024. I also can't use 

DATEADD(dim_date[date], -364, DAY), because it woudn't calculate correctly on leap year.

 

I have a column in my dim_date table called 'comparisondate', which correctly shows 2/3/2024 for the 2/1/2025 record.

 

Does anyone know what is the best way to calculate sales for the comparison date, when I have the 'date' field selected in a slicer? I usually am using a date range, instead of just one date, so I can't use SELECTEDVALUE. So when I select 2/1/2025 - 2/28/2025 in the date slicer, I would like to calculate sales for 2/3/2024 - 3/1/2024.

 

Any responses would be appreciated. Thank you!

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

@user5341567 

If you already have comparisondate defined in dim_date, then this is how I would write it:

 

Sales LY =
CALCULATE (
    [Sales Measure],
    TREATAS ( VALUES ( dim_date[comparisondate] ), dim_date[date] )
)

 

 

As long as dim_date is marked as a date table, this will remove any filters on dim_date and apply the values of dim_date[comparisondate] as a filter on dim_date[date].

 

Does this work for you?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

4 REPLIES 4
OwenAuger
Super User
Super User

@user5341567 

If you already have comparisondate defined in dim_date, then this is how I would write it:

 

Sales LY =
CALCULATE (
    [Sales Measure],
    TREATAS ( VALUES ( dim_date[comparisondate] ), dim_date[date] )
)

 

 

As long as dim_date is marked as a date table, this will remove any filters on dim_date and apply the values of dim_date[comparisondate] as a filter on dim_date[date].

 

Does this work for you?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

This worked perfectly! So glad to see this. I appreciate your response!

Greg_Deckler
Community Champion
Community Champion

@user5341567 Maybe something like this:

Measure Date LY Comparison =
  VAR __Date = DATE( 2025, 2, 1 )
  VAR __Year = YEAR( __Date )
  VAR __WeekNum = WEEKNUM( __Date )
  VAR __WeekDay = WEEKDAY( __Date )
  VAR __Result = 
    MAXX(
      FILTER( 'Calendar', YEAR( [Date] ) = __Year - 1 && WEEKNUM( [Date] ) = __WeekNum && WEEKDAY( [Date] ) = __WeekDay ),
      [Date]
    )
RETURN
  __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thank you for taking the time to respons. Unfortunately, as I'm using a date range slicer, it doesn't seem to be calculating correctly. It shows as blank when I have 2/1 - 2/1 in the date slicer. Even though it's a single date, I think it's being thrown off becasue the slicer is a 'between' format:

 

user5341567_0-1741209770284.png

 

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.