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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Calculating Last Week Last Year

Hi all,

 

I am trying to create a measure that returns the week end date last year. The week end date is always need to be on a Saturday, which causes some problems when trying to account for the one day offset so doing a dateadd with -364 days doesn't work in the long term. For example:

Week number 1 in 2020 - 04/01/2020

Week number 1 in 2021 - 02/01/2020

Week number 1 in 2022 - 01/01/2020

Week number 1 in 2023 - 07/01/2020

 

The date table I am using has a "Date Key" and a "Week End Date" on the same row, as well as a week number - see below:

Date Table example.PNG

I have tried using IF(HASONEVALUE('DimensionDate'[Calendar Year]),CALCULATE(VALUES('DimensionDate'[Week End Date]),FILTER(ALL('DimensionDate'),AND('DimensionDate'[Calendar Year]=VALUES('DimensionDate'[Calendar Year])-1,CONTAINS(VALUES('DimensionDate'[Calendar Week Number]),'DimensionDate'[Calendar Week Number],'DimensionDate'[Calendar Week Number]))))))

 

But this does not work for the start weeks of the year, as some "Week End Dates" technically have two Calendar Years.

 

Apologies if I haven't explained this very well, but any help on calculating "Week End Date" based on Saturdays would be a great help!

 
 
 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi,

 

I managed to figure it out - maybe I wasn't so clear on the explanation but the end result might help! Here is the measure I ended up with:

 

LOOKUPVALUE('DimensionDate'[Week End Date],'DimensionDate'[Year & Cal WeekNum],VALUES('DimensionDate'[Year & Cal WeekNum])-100)

 

This returns the week end date for last year - just need to factor in years with 53 weeks and then I am all set.

 

Thanks for the advice though!

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi,

 

Thank you for your quick responses and apologies for not explaining it very well. It is my first post here so thanks for explaining how to get posts answered @Greg_Deckler 

 

I have uploaded a sample file to dropbox (https://www.dropbox.com/s/1l2xpcc1z2lje5o/Last%20Week%20Last%20Year%20Example.xlsx?dl=0)

 

Column E contains the expected result, but ideally it would be good to have it as a measure rather than a calculated column.

 

I hope that helps and thanks again!

 

 

 

Anonymous
Not applicable

Hi,

 

I managed to figure it out - maybe I wasn't so clear on the explanation but the end result might help! Here is the measure I ended up with:

 

LOOKUPVALUE('DimensionDate'[Week End Date],'DimensionDate'[Year & Cal WeekNum],VALUES('DimensionDate'[Year & Cal WeekNum])-100)

 

This returns the week end date for last year - just need to factor in years with 53 weeks and then I am all set.

 

Thanks for the advice though!

@Anonymous 

Seems like already solved it. Typically same week day is 364 days behind. As you already have formula to find week end date you can use that on date that is 364 days behind.

Can you mark you reply as solution, so that other can take hekp

CheenuSing
Community Champion
Community Champion

Hi @Anonymous ,

 

I am not too clear about requirements.  Can you create an excel sheet of dates  with the result you are expecting and paste it here.

 

As requested by you to calculate the weekend date based on Saturday you can use the calculated column as

 

Column = [Date] - MOD([Date]-1, 7) + 6
 
The date here refers to the date column of your date table.
 
Cheers
 
CheenuSing
 
Did I answer your question? Mark my post as a solution and also give KUDOS !

Proud to be a Datanaut!
Greg_Deckler
Super User
Super User

I'm not sure I am 100% following this but I have a ton of date/week manipulations in the Quick Measures gallery that you can check out. Can you provide some sample data in text and your expected output? Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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