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

Calculation Sales Last 12 months, context CalendarYearWeekISO, problem with weeks 52 and 53

Hi everyone,

 

I want to compare the Sales of the last 12 months weekly and then for the context CalendarYearWeekISO.

 

Datamodel:

181012 Datamodel.JPG

 

Time Measures:

 

FirstDate TW = FIRSTDATE( 'Calendar'[FirstDateOfWeek])

 

FirstDate LTM -1W =
CALCULATE([FirstDate TW];
    FILTER(ALL('Calendar');
        'Calendar'[Year] = MAX('Calendar'[Year] ) -1 &&
        'Calendar'[WeekOfYearISO] - 1= max ('Calendar'[WeekOfYearISO])

 

FirstDate LTM -1W TEST =
VAR CurrentWeek = SELECTEDVALUE('Calendar'[WeekOfYearISO])
VAR CurrentYear = SELECTEDVALUE('Calendar'[Year])
VAR MaxWeekNumber = CALCULATE(max('Calendar'[WeekOfYearISO] ); ALL('Calendar') )
RETURN
CALCULATE([FirstDate TW];
    FILTER(ALL('Calendar');
        IF( CurrentWeek = 52;
           'Calendar'[WeekOfYearISO] = CurrentWeek -51 && 'Calendar'[Year] = CurrentYear;
           IF( CurrentWeek = 53;
           'Calendar'[WeekOfYearISO] = CurrentWeek -52 && 'Calendar'[Year] = CurrentYear;
           'Calendar'[WeekOfYearISO] = CurrentWeek + 1 && 'Calendar'[Year] = CurrentYear -1))))

 

LastDate TW = LASTDATE ( 'Calendar'[LastDateOfWeek])

 

FirstDate PP LTM -1W =
CALCULATE([FirstDate TW];
    FILTER(ALL('Calendar');
        'Calendar'[Year] = MAX('Calendar'[Year] ) -1 &&
        'Calendar'[WeekOfYearISO] = max ('Calendar'[WeekOfYearISO])
    )
)

 

LastDate PP LTM - 1W = DATEADD(LASTDATE('Calendar'[LastDateOfWeek]);-7;DAY)

 

As you can see in the following photo's, I have some null dates:

 

181012 Photo 1.JPG181012 Photo 2.JPG

To compare weekly you have to know what the maximum weeknumber of the year prior was.

If the max. weeknumber lastyear = 52 than the calculations for the week 1 until 51 are as follows:

 

181012 Photo 3.JPG

 

If the max. weeknumber lastyear = 53 than the calculations are:

 181015 Photo Community.JPG

 

 

I know, it also looks like mathematics to me but can someone help me with the correct Dax-formulas?

 

Thanks in advance,

 

Cor

 

PS: I don't have OneDrive or Dropbox and I don't know how to send a demo pbix-file.....

 

@Zubair_Muhammad

1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@Anonymous,

 

There are only 52 weeks in year 2003. Also check if the column [Year] is correct.

Community Support Team _ Sam Zha
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

1 REPLY 1
v-chuncz-msft
Community Support
Community Support

@Anonymous,

 

There are only 52 weeks in year 2003. Also check if the column [Year] is correct.

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

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.

Top Solution Authors