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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
DemoFour
Responsive Resident
Responsive Resident

Moving month by month Running total

Hay peeps, 

My customer wants a moving month by month running total, so that it always shows the last 12 months regardless of year. 

Output = Open and closed totals for last 12 months  Open = Line Closed = Bars - So this month it would show the proceding 12 months, then next month this will change to the previous months.  

I have a data model built on a star schema with a date table, but this not a requirement I have been asked before, as generally it is last FY or last Year not a moving year!  So any pointers would be much appreciated. 

Current Running Total measures I am trying: 

 

Running total = 
CALCULATE(
    [Count],
    DATESYTD( 'Date'[Date])
)

 



 

RT = 
VAR _MaxDate = MAX( 'Date'[Date])
RETURN
CALCULATE(
    [Count],
    'Date'[Date] <= _MaxDate,
    ALL( 'Date' )
)

 

 Thanks in advance

1 ACCEPTED SOLUTION

You ar eright. My mistake. Excuse me

RT =
VAR _MaxDate = MAX( 'Date'[Date])

var datemoins1an=date(Year(_MaxDate),Month(_MaxDate)-12,day(_MaxDate))
return
CALCULATE (
[count] ,
 'Date'[Date]>=datemoins1an&& 'Date'[Date]<=_MaxDate,ALL ( 'Table' )
)

 

View solution in original post

5 REPLIES 5
JamesFR06
Resolver IV
Resolver IV

Hi, You can try this code

 

Rolling Sum Last 12 months =
CALCULATE (
[count] ),
ALL ( 'Table' ),
DATESBETWEEN (
'Calendar'[Date],
DATEADD ( _MaxDate, -11, MONTH ),
MaxDate )
)
)

Morning @JamesFR06 

Thanks for the reply, is _MaxDate a VAR _MaxDate = MAX( Date[Date] ) ? 

Hi @DemoFour 

 

Yes this is your var in your exemple. Sorry.

@JamesFR06  That's cool, I tried to add this in but DATEADD() says it will not take a Variable as the parameter? DATEADD( Dates, Number of Interval. Interval)  

You ar eright. My mistake. Excuse me

RT =
VAR _MaxDate = MAX( 'Date'[Date])

var datemoins1an=date(Year(_MaxDate),Month(_MaxDate)-12,day(_MaxDate))
return
CALCULATE (
[count] ,
 'Date'[Date]>=datemoins1an&& 'Date'[Date]<=_MaxDate,ALL ( 'Table' )
)

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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