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.
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
)
)
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.
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
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
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
47 | |
24 | |
20 | |
15 | |
13 |
User | Count |
---|---|
55 | |
48 | |
43 | |
19 | |
19 |