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
pokdbz
Helper II
Helper II

Need Last Year 4 Week Aggregate

How can I create a calculation that looks back one year and then does a 4 week aggregate?

We do not use a standard calendar so some of the DAX functions do not work becauses of this.

 

Currently this is what I use for a 4 week/28 day aggregate.  How can I add the Last Year look back to this?

CALCULATE (
[Sales],
DATESINPERIOD (
'Calendar - Fiscal'[Date],
LASTDATE ( 'Calendar - Fiscal'[Date] ),
-28,
DAY
)
)

5 REPLIES 5
Anonymous
Not applicable

Maybe this would help you?

 

https://www.youtube.com/watch?v=wHn968f1E58

 

Best

Darek

Anonymous
Not applicable

For a regular calendar this should work:

 

[Measure] =
CALCULATE (
    [Sales],
    DATESINPERIOD (
        'Calendar - Fiscal'[Date],
        SAMEPERIODLASTYEAR( LASTDATE ( 'Calendar - Fiscal'[Date] ) ),
        -28,
        DAY
    )
)

But beware! If the dates go off the beginning of the calendar, you will not get a full 28-day period. You have to decide what you want to do in case the shift does not return 28 days.

 

I also hope that 'Calendar - Fiscal' is a PROPER DATE TABLE and is marked as such. Otherwise, this stuff will not work.

 

Best

Darek

This is a proper date table, but its not a standard Calendar table.  Its a Fiscal Calendar so alot of the functions will not work.  We cannot hard coded dates either because the next year does not start and end on the same as the previous year.

 

Anonymous
Not applicable

To be able to move in time in a custom calendar you need to create columns that will enable this. For instance, all days should have attributes like: FiscalYearNumber, FiscalYearName, FiscalMonthNumberInYear, FiscalMonthConsecutiveNumberAcrossAllYears,....

 

Once you have them (please have a look at the YT vid link I've sent you before), then and only then can you build your calculations. 

 

For calculations when using custom calendars please go to Period Comparison Patterns with Custom Calendars

 

Best

Darek

Anonymous
Not applicable

What does it mean when you say "last year"? Are you talking about the usual year shift in the ordinary calendar or something like a custom year (say, fiscal)?

 

Best

Darek

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