Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
BItoken
Helper III
Helper III

Trailing 12 months DAX

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.

 

BItoken_0-1599859842042.png

 

I tried this DAX Statement

Trailing 12 Months = CALCULATE(SUM([Sales]), DATESINPERIOD([Date]),ENDOFMONTH([Date]),-4,QUARTER))
This may not work as the Date is rolled up to quarter level.

Any help is much appreciated.

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@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.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

Anonymous
Not 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
        )    )

Training 12 months DAX.JPG

Best Regards

Rena

View solution in original post

9 REPLIES 9
Ray_Minds
Continued Contributor
Continued Contributor

Hi @BItoken 

Create Measure # 12 Month Rollback =CALCULATE((SUM('Fact Table '[Amount]),DATESINPERIOD('Dim Date'[Date],MAX ('Dim Date '[Date]), -12, Month))

If your requirement is solved, please make THIS ANSWER a SOLUTION ✔️ and help other users find the solution quickly. Please hit the LIKE 👍 button if this comment helps you.


amitchandak
Super User
Super User

@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.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

This solution worked. Thanks @amitchandak 

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. 

Anonymous
Not 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
        )    )

Training 12 months DAX.JPG

Best Regards

Rena

@BItoken , Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi,

Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
FrankAT
Community Champion
Community Champion

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):

 

12-09-_2020_00-19-47.png

 

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

 

BItoken_0-1599922764663.png

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors