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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Berl21
Helper III
Helper III

Rolling sales from the last 24 months

Hi,

 

management wants to see the accumulated sales until now vs the accumulated sales from the last two years in a graphic displaying the last 24 months.

I have written this measure for the rolling numbers, thinking that MAX Date was related to our current time (today). Instead, Max date looks at row level and so it computes rolling numbers backwards, which is not what we want.

Sales cumulated rolling =

CALCULATE (
[Total Sales],
DATESINPERIOD ( 'Datetable'[Date],
MAX ( 'Datetable'[Date] ),
-24,
MONTH
))

 

With this, I will see the accumulated sales with May 2022 as a label but including numbers from 2020. What I need is basically the raw numbers since January 2022, accumulated.

I have looked around, but I am lost. Can someone help here?

Thanks!

Pauline.


4 REPLIES 4
talespin
Solution Sage
Solution Sage

hi @Berl21 ,

 

If you can share pbix file with any sensitive data removed that will help. This is what you can try

 

Create a Measure(Assuming you have date field in your visual)

 
//This variable will capture the current date(current filter context).
VAR _dt = SELECTEDVALUE(Date)
 
//In CALCULATE first you will remove any filter on date table column. Then provide a new filter for sales calculation, Date >= 24 months prior from date in current filter context and less than equal to date in current filter context.
CALCULATE( [Total Sales], ALL(Dates[column in visual]), Date >= EDATE(_dt, -24), Date <= _dt )
 
If this is not what you want, please explain.
Greg_Deckler
Community Champion
Community Champion

@Berl21 Try this, just use SUMX instead of AVERAGEX: Better Rolling Average - Microsoft Fabric Community



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi,

I still have the issue with the backward calculation. Don't know how to get around this, maybe the issue is that the date table should be switched for another one.

The last available date in this table is 31st of December 2030. Instead of today.

Hence, this can't work either:
VAR __DATE_PERIOD =
DATESBETWEEN(
'Datetable'[Date].[Date],
STARTOFMONTH(DATEADD(__LAST_DATE, -24, MONTH)),
ENDOFMONTH(DATEADD(__LAST_DATE, 0, MONTH))

How can I replace these lines?

@Berl21 I don't see why that makes a difference how many dates are in the Dates table. What matters is what date is in context at the time and for dates beyond today, you can just add a condition where if that is the case, return BLANK.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.