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

WTD Last Year Calculation

Hello, 

 

I am trying to compute WTD Last Year for Sales Data. I have computer WTD this year using either or these formulas: 

 

WTD TY Sales = CALCULATE(SUM([Dollars_Sold]),DATESINPERIOD(Sales[Calendar Date],LastDate(Sales[Calendar Date]),-WEEKDAY(LastDate(Sales[Calendar Date])),DAY))

 

or

 

WTD TY Sales = CALCULATE(SUM(Sales[Dollars_Sold]),LASTDATE(Sales[Calendar Date]))

 

I have tried to adjust these formulas to show me same WeekNumber last year (ie 2017), but I have not been able to do it. Does anyone know how I can compute it?

1 ACCEPTED SOLUTION

Hi @Anonymous,

 

Please check out the demo in the attachment and try the measure like this.

Measure =
CALCULATE (
    SUM ( FactSales[salesquantity] ),
    FILTER (
        ALL ( 'Calendar' ),
        YEAR ( [Date] )
            = YEAR ( MIN ( [Date] ) ) - 1
            && 'Calendar'[WeekNum] = MIN ( 'Calendar'[WeekNum] )
    )
)

WTD-Last-Year-Calculation

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

11 REPLIES 11
v-jiascu-msft
Employee
Employee

Hi @Anonymous,

 

Could you please mark the proper answers as solutions?

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
kazael
Helper I
Helper I

Are you trying to present sales between the same week number last year and current date?

Anonymous
Not applicable

Yes! We are trying to present sales during the same week TY vs. LY

Hi @Anonymous,

 

Please check out the demo in the attachment and try the measure like this.

Measure =
CALCULATE (
    SUM ( FactSales[salesquantity] ),
    FILTER (
        ALL ( 'Calendar' ),
        YEAR ( [Date] )
            = YEAR ( MIN ( [Date] ) ) - 1
            && 'Calendar'[WeekNum] = MIN ( 'Calendar'[WeekNum] )
    )
)

WTD-Last-Year-Calculation

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Chihiro
Solution Sage
Solution Sage

It is near impossible to align weeks perfectly over different year.

 

Ex:

Using WEEKNUM([Date], 21) i.e. ISO 8601 week number.

Year 2020 will have week number 53. Where as 2017 to 2019 will have 52.

 

 

When comparing different years, I tend to use one of following methods depending on the need.

 

1) Average of value by weekday in a given month of year and compare to previous year.

2) Compare at monthly level

3) Compare based on day of year (i.e. 1~365/366), if there is no intra week pattern.

4) Compare week over week, without year constraint.

etc.

Anonymous
Not applicable

We are in a retail environment, so we are using a 4-5-4 calendar. 

 

So we will be able to compare the same week number in different years. 

Hmm? Would some year not have 53 weeks instead of 52 weeks in 4-5-4 format still? Occuring every 5 to 6 years?

 

Do you have dimension table where 2017 is restated (i.e. ignoring first week of the year 2017)? Or is 53rd week being ignored?

 

At any rate, it would help if you have model along with calendar dimension table (4-5-4 mapping).

 

Anonymous
Not applicable

It is restated, so the dates may not match exactly, but the week number will remain the same. 

 

So how is your table structured?

Without it, bit hard to give you exact formula. Can you upload sample?

 

fyi - if you don't have calendar dimension table. I'd recommend adding one. It makes time intelligence calculation so much easier to do.

 

As an example. If you have WeekNum, Year, WeekDay columns in fact table (without calendar)...

Then you'd do something like.

CurrentWk = CALCULATE(Max('Table'[WeekNum]),Filter(ALL('Table'),'Table'[Date]=MAX('Table'[Date])))

WTD Current = CALCULATE(SUM('Table'[Value]),Filter('Table',[WeekNum]=[CurrentWk]))

WTD LastYr = CALCULATE(SUM('Table'[Value]),Filter('Table',[WeekNum]=[CurrentWk]&&[Year]=Year(MAX('Table'[Date]))-1&&[WeekDay]<=WEEKDAY(MAX('Table'[Date]),2)))

Anonymous
Not applicable

Calendar_DateCalendar_Date_StringCalendar_MonthCalendar_DayCalendar_YearCalendar_QuarterDay_NameDay_of_WeekDay_of_Week_in_MonthDay_of_Week_in_YearDay_of_Week_in_QuarterDay_of_QuarterDay_of_YearWeek_of_MonthWeek_of_QuarterWeek_of_YearMonth_NameFirst_Date_of_WeekLast_Date_of_WeekFirst_Date_of_MonthLast_Date_of_MonthFirst_Date_of_QuarterLast_Date_of_QuarterFirst_Date_of_YearLast_Date_of_YearIs_Leap_YearDays_in_MonthMerchant_Day_of_YearMerchant_Week_of_YearMerchant_Calendar_MonthMerchant_Calendar_QuarterMerchant_First_Date_of_WeekMerchant_Last_Date_of_WeekMerchant_First_Date_of_MonthMerchant_Last_Date_of_MonthMerchant_First_Date_of_QuarterMerchant_Last_Date_of_QuarterMerchant_First_Date_of_YearMerchant_Last_Date_of_YearISO_Day_of_WeekISO_Day_of_YearISO_Week_of_YearISO_First_Date_of_WeekISO_Last_Date_of_WeekISO_StringFiscal_Day_of_YearFiscal_Week_of_YearFiscal_QuarterFiscal_MonthFiscal_First_Date_of_YearFiscal_Last_Date_of_YearSeason
Sunday, August 6, 20178/6/20178620173Sunday11326372182632AugustSunday, August 6, 2017Saturday, August 12, 2017Tuesday, August 1, 2017Thursday, August 31, 2017Saturday, July 1, 2017Saturday, September 30, 2017Sunday, January 1, 2017Sunday, December 31, 2017False311902873Sunday, August 6, 2017Saturday, August 12, 2017Sunday, July 30, 2017Saturday, August 26, 2017Sunday, July 30, 2017Saturday, October 28, 2017Sunday, January 29, 2017Saturday, February 3, 2018721731Monday, July 31, 2017Sunday, August 6, 20172017-W31-731046411Saturday, October 1, 2016Saturday, September 30, 2017Fall

 

Above is an example of the schema.

 

I tried the formulas, the WTD TY worked but the WTD LY gives me no result. Here are the formulas I used.

 

Current Week = CALCULATE(MAX('Date'[Merchant_Week_of_Year]), FILTER(ALL('Sales'), Sales[Calendar Date] = MAX(Sales[Calendar Date])))

Last Year = YEAR(MAX(Sales[Calendar Date]))-1

WTD TY Test = CALCULATE(SUM(Sales[Dollars_Sold]),FILTER('Date',[Merchant_Week_of_Year]=[Current Week]))

WTD LY Test = CALCULATE(SUM(Sales[Dollars_Sold]),FILTER('Date',[Merchant_Week_of_Year]=[Current Week]&&'Date'[Calendar Year]=[Last Year]&&'Date'[Day_of_Week]<=WEEKDAY(MAX(Sales[Calendar Date]),2)))

 

Can you upload dummy data to cloud share storage? With desensitized info and just enough data to demonstrate your need.

 

It will be so much easier to help you with it.

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.