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

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.

Reply
Saskwyt
Frequent Visitor

12 Month Rolling Cumulative Sales

Hi,

 

I wondered if someone can help me please? After searching the forum I can't quite find an appropriate answer.

 

What i'm trying to achieve is a rolling 12 months cumulative sales. So that when I change the "To Date" on the date slicer it automatically looks back 12 months and calculates the cumulative sales.

 

Data in the model:

I have a list of orders with dates and values from 2020 to 2023 - This comes from a spreadsheet and is called Excel_Data in the model. I also have a date table which is linked to the Excel_Data table.

I also have a DAX measure called YTD_SALES_CY:

YTD_SALES_CY = 
CALCULATE(Sum(Excel_Data[CompanyNotesCost]),
    FILTER(
        ALL(Date_Table),
        And(Date_Table[Date]<= Max(Date_Table[Date]),
            Date_Table[Date]>eomonth(CALCULATE(MAX(Date_Table[Date]), ALLSELECTED(Date_Table)),-14)
            )
          )
        )

 

The DAX measure I have above seems to be pretty close. The issue seems to be with the "From date" as this doesn't change when the "To Date" changes.

In simple terms - When I enter 31/12/2022 as my "To Date" in the slicer, I get 12 months worth of data. When I select 31/01/2023 as my "To Date" I get 13 months of data, 28/02/2023 I get 14 months of data, 30/06/2022 I get 6 months of data. I want to always have 12 months of data looking back from my "To Date"

 

Please see below a link to my file and many thanks in advance!!

 

https://t4designlimited-my.sharepoint.com/:u:/g/personal/markshort_t4design_com/EVExCE3KLOlAmCKBARpz...

2 REPLIES 2
Saskwyt
Frequent Visitor

Hi @ValtteriN thank you so much for your response. I'm so sorry but i don't fully understand your answer.

 

I've added a new measure to the file based on what I think is needed but this doesn't give me the right answer.

 

Could you explain in a bit more detail and perhaps provide a specific solution in the file?

https://t4designlimited-my.sharepoint.com/:u:/g/personal/markshort_t4design_com/EVExCE3KLOlAmCKBARpz...

 

Thanks again!

ValtteriN
Super User
Super User

Hi,

For rolling 12M I usually use this kind of structure:

CALCULATE ( selectedmeasure(), DATESBETWEEN ( 'Calendar'[Date], DATEADD ( LASTDATE ( DATEADD ( 'Calendar'[Date], -12, MONTH ) ), +1, DAY ), LASTDATE ( 'Calendar'[Date] ) )  )


Just place your calculation logic in the "selectedmeasure()" slot.





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

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors