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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Quinnie2017
Helper II
Helper II

My Day Week Year (DWY) formula needs improvement!

THE SITUATION:

Based upon good advice from @CheenuSing from this post I created a DWY column:

 
DWY = WEEKDAY('Day Key'[Business Date])*10000000
+ WEEKNUM('Day Key'[Business Date])*10000
+ YEAR('Day Key'[Business Date])

 

Then I use DWY to calculate sales difference between this year and same day of week last year.  For example:

  • Thursday, February 11, 2021 is DWY 50072021
  • Same day last year, Thursday, February 13, 2020 is DWY 50072020

So to get last year sales I use:

 

LY Sales = Calculate([CY Sales], Filter(ALL('Day Key'),'Day Key'[DWY] = MAX( 'Day Key'[DWY]) -1 ))
 
This works perfectly until I get to the following situation:
  • Thursday, December 31, 2020 is DWY 50532020
  • Same day last year, Thursday, January 2, 2020 is DWY 50012020

THE PROBLEM: My DWY solution no longer works because LY Sales is looking for 50532019 but there is no 50532019.

 

WHAT I NEED: My DWY statement needs improved to create a unique number solution to account for weird calendar situations like December 31, 2020 vs January 2, 2020.

 

Sample data here.

 

Any help would be appreciated.

1 ACCEPTED SOLUTION
CheenuSing
Community Champion
Community Champion

Hi @Quinnie2017 ,

 

You could try using the measure

 

Same Week Day Last year =CALCULATE([Sales], dateadd('Date'[Date],-364,Day))

 

Let me know if this worked for you.

 

Cheers

 

CheenuSing

Did I answer your question? Mark my post as a solution and also give KUDOS !

Proud to be a Datanaut!

View solution in original post

7 REPLIES 7
Robbief
Helper II
Helper II

Just ran into this one myself......  Did you come up with a solution for it?

HI @Robbief ,
The solution is in the thread itself. Check it out.

 

Cheers

CheenuSing

Did I answer your question? Mark my post as a solution and also give KUDOS !

Proud to be a Datanaut!

O wow - This works for leap years too.....

CheenuSing
Community Champion
Community Champion

Hi @Quinnie2017 ,

 

You could try using the measure

 

Same Week Day Last year =CALCULATE([Sales], dateadd('Date'[Date],-364,Day))

 

Let me know if this worked for you.

 

Cheers

 

CheenuSing

Did I answer your question? Mark my post as a solution and also give KUDOS !

Proud to be a Datanaut!

Perfect!  I thought I might need to change it to this.  And this works on a leap year too!  Kudos - I will mark as solution and thanks again!

danextian
Super User
Super User

hi @Quinnie2017 , I am assuming that if the corresponding LY week does not exist it should return  blank or zero. Have you tried wrapping LY sales with a conditional formula so if LY does not exisit the difference is just the current year?










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Unfortunately this would not be acceptable as there should always be LY sales in our dataset, thanks for the reply!

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.