cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Zabeer
Helper I
Helper I

Rolling 12 month sum with two filters

Hello. I am struggling with a particular dax expression for the below problem. I would like to create a calculated column that gives the rolling 12 month sum per customer per category. There are many more customers and categories.
Sample data :

CustomerCategoryDateValueExpected result (rolling 12 month sum)
AF01/01/20191010
AF01/02/2019212
AF01/03/2019719
AF01/04/2019423
AF01/05/2019326
AF01/06/2019430
AF01/07/2019535
AF01/08/2019237
AF01/09/2019643
AF01/10/2019346
AF01/11/2019147
AF01/12/2019552
AF01/01/2020244
AF01/02/2020850

 

1 ACCEPTED SOLUTION
dax
Community Support
Community Support

Hi @Zabeer , 

You also could refer to below measure to see whether it work or not

Measure =
CALCULATE (
    SUM ( 'Table'[Value] ),
    FILTER (
        ALLSELECTED ( 'Table' ),
        'Table'[Date]
            > DATE ( YEAR ( MIN ( 'Table'[Date] ) ), MONTH ( MIN ( 'Table'[Date] ) ) - 12, 1 )
            && 'Table'[Date] <= MIN ( 'Table'[Date] )
    )
)

 

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
dax
Community Support
Community Support

Hi @Zabeer , 

You also could refer to below measure to see whether it work or not

Measure =
CALCULATE (
    SUM ( 'Table'[Value] ),
    FILTER (
        ALLSELECTED ( 'Table' ),
        'Table'[Date]
            > DATE ( YEAR ( MIN ( 'Table'[Date] ) ), MONTH ( MIN ( 'Table'[Date] ) ) - 12, 1 )
            && 'Table'[Date] <= MIN ( 'Table'[Date] )
    )
)

 

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Mariusz
Community Champion
Community Champion

Hi @Zabeer 

 

You can use DATESINPERIOD
https://docs.microsoft.com/en-us/dax/datesinperiod-function-dax

 

Please see the DAX Mesure example below.

Sales Rolling 12 months = 
CALCULATE(
    [Sales],
    DATESINPERIOD( 'Calendar'[Date], MIN( 'Calendar'[Date] ) -1, -12, MONTH )
)

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

@Zabeer similar posts on it and you can change it as per your business rules

 

https://www.sqlbi.com/articles/rolling-12-months-average-in-dax/

 

https://www.accountingweb.co.uk/business/finance-strategy/power-bi-rolling-12-months-and-ytd






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





Helpful resources

Announcements
Exciting changes

Power BI Community Changes

Check out the changes to the Power BI Community announced at Build.

May 2023 update

Power BI May 2023 Update

Find out more about the May 2023 update.

Kudo Data Story carousel

Data Stories Gallery

Visit our Data Stories Gallery and give kudos to your favorite Data Stories.

Top Solution Authors