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.
Hi,
I have a Date column that is rolled up to the end of the quarter (Date) as per the attached image and the corresponding Fiscal Year ( Fiscal Qtr ).
I am struggling with getting a trailing 12 months (or 4 quarters) of the Sales column for the last 4 qtrs calculated at each corresponding quarters.
Trailing 12 Months Expected Output - is what i am looking for.
I tried this DAX Statement
Any help is much appreciated.
Solved! Go to Solution.
@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.
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.
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.
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 , Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.
Hi,
Share the link from where i can download your PBI file.
Hi @BItoken
this may be a solution. I added the column Fiscal Year with Power Query and used it in the measure (see attached pbix file):
Trailing 12 Month =
CALCULATE(
[Sum of Sales],
FILTER(
ALLEXCEPT(
'Table',
'Table'[Fiscal Year]
),
'Table'[Fiscal Qtr] <= MAX('Table'[Fiscal Qtr])
)
)
With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)
Hi @FrankAT
Your DAX query will get me the sum of all previous quarters Sum.
What i need to derive is the sum of last 4 trailing quarters for any given Qtr.
For example FY 21 Q1 value should be the sum of: FY21 - Q1, FY20 - Q4, FY20 - Q3, FY20 - Q2
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 |
---|---|
105 | |
93 | |
75 | |
62 | |
50 |
User | Count |
---|---|
146 | |
109 | |
106 | |
88 | |
61 |