Forum Discussion
CALENDAR TABLE - DAX Last 12 months
- 8 years ago
In your scenario, you want to create the calendar table dynamically. Right?
First you should know that we can use TODAY() function to get current date. Then to achieve your requirement, you can refer to following DAX:
1. To create a 7 years calendar table based on today:
Table = CALENDAR(DATE(YEAR(TODAY())-7,MONTH(TODAY()),DAY(TODAY())),TODAY())
2. Get last 12 month:
Last 12 month = DATE(YEAR(TODAY())-1,MONTH(TODAY()),DAY(TODAY()))
Also, you can change the date format in Data pane.
Thanks,
Xi Jin.
In your scenario, you want to create the calendar table dynamically. Right?
First you should know that we can use TODAY() function to get current date. Then to achieve your requirement, you can refer to following DAX:
1. To create a 7 years calendar table based on today:
Table = CALENDAR(DATE(YEAR(TODAY())-7,MONTH(TODAY()),DAY(TODAY())),TODAY())
2. Get last 12 month:
Last 12 month = DATE(YEAR(TODAY())-1,MONTH(TODAY()),DAY(TODAY()))
Also, you can change the date format in Data pane.
Thanks,
Xi Jin.
This will filter the fact based on the date dimension. Worked for me
Amount-Previous2Years = VAR Months = -24 VAR FromDate = CALCULATE(EOMONTH(MAX(DimDate[Full Date])+1, Months), FctSales) RETURN CALCULATE(SUM(FctSales[Amount]), DimDate[Full Date]>=FromDate)