Forum Discussion
Trailing 12 months DAX
- 5 years ago
BItoken , You formula seems correct, you need use MAx of date. End of month will not apply in your case
Trailing 12 Months = CALCULATE(SUM(Table[Sales]), DATESINPERIOD(Date[Date],Max(Date[Date]),-4,QUARTER))
or
Trailing 12 Months = CALCULATE(SUM(Table[Sales]), DATESINPERIOD(Date[Date],Max(Table[Date]),-4,QUARTER))
Always use date table. As solution might work without that, but will create issue in future.
To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/
Appreciate your Kudos. - Anonymous5 years ago
Hi BItoken ,
I created a sample pbix file for you, please check if that is what you want.
1. Create a calculated column to order by the data base on the fiscal quarter
Rank = RANKX ( 'Sales', 'Sales'[Fiscal Qtr],, ASC, DENSE )2. Create a measure to get the rolling 4 quaraters sales
Trailing 12 Months = VAR _index = MAX ( 'Sales'[Rank] ) VAR _date = MAX ( 'Sales'[Date] ) RETURN CALCULATE ( SUM ( 'Sales'[Sales] ), FILTER ( ALL ( 'Sales' ), 'Sales'[Rank] >= _index - 3 && 'Sales'[Rank] <= _index && 'Sales'[Date] <= _date ) )Best Regards
Rena
BItoken , You formula seems correct, you need use MAx of date. End of month will not apply in your case
Trailing 12 Months = CALCULATE(SUM(Table[Sales]), DATESINPERIOD(Date[Date],Max(Date[Date]),-4,QUARTER))
or
Trailing 12 Months = CALCULATE(SUM(Table[Sales]), DATESINPERIOD(Date[Date],Max(Table[Date]),-4,QUARTER))
Always use date table. As solution might work without that, but will create issue in future.
To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/
Appreciate your Kudos.
- BItoken5 years agoHelper III
Hi amitchandak ,
I used this DAX function.
Although, i get the same values of Sales.
My Fiscal Qtr and Date and Sales are all in the same table.
- Ashish_Mathur5 years agoSuper User
Hi,
Share the link from where i can download your PBI file.
- amitchandak5 years agoSuper User
BItoken , Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.
- Anonymous5 years agoNot applicable
Hi BItoken ,
I created a sample pbix file for you, please check if that is what you want.
1. Create a calculated column to order by the data base on the fiscal quarter
Rank = RANKX ( 'Sales', 'Sales'[Fiscal Qtr],, ASC, DENSE )2. Create a measure to get the rolling 4 quaraters sales
Trailing 12 Months = VAR _index = MAX ( 'Sales'[Rank] ) VAR _date = MAX ( 'Sales'[Date] ) RETURN CALCULATE ( SUM ( 'Sales'[Sales] ), FILTER ( ALL ( 'Sales' ), 'Sales'[Rank] >= _index - 3 && 'Sales'[Rank] <= _index && 'Sales'[Date] <= _date ) )Best Regards
Rena
- BItoken5 years agoHelper III
This solution worked. Thanks amitchandak