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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
jatin_
Frequent Visitor

Restart running total in DAX BASED ON MEASURE

Hi Team,

I used below formula to retrieve the cumulative total of last 9 months of a mesure.

"Cumulative 9 months =
Var N1=SUMMARIZE(FILTER(ALL('Date'),[Month Year]<=MAX('Date'[Month Year])),'Date'[Month Year],"Sum",'Measures Table'[Monthly Value])
Var N2=TOPN(9,N1,[Month Year],DESC)
return
IF([last 4 months]=0,0 ,SUMX(N2,[Sum]))"

The formula was shared by @v-zhangti  in my previous post

jatin__0-1653637587594.png

The formula seems to be working fine however I would  like the running total of 9 months to reset at 2022-01 as it hits 0 and then only cumulate afterwards upto 9 Months and not from the begining of the data. 

Your inputs are appreciated. Thanks 

4 REPLIES 4
v-yiruan-msft
Community Support
Community Support

Hi @jatin_ ,

You can refer the following blog to achieve it.

Power Query method:

Accumulative, conditional accumulative in Power Query

yingyinr_0-1653988526759.png

DAX method:

Cumulative Sum column. Resets if row value = 0

yingyinr_1-1653989081977.png

Cumulative sum that resets every year

Best Regards

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

Hi @v-yiruan-msft , Thanks for sharing your solution. I tried following the DAX approach as it fits more to my problem however despite getting all the variant correctly(can be seen in pic below), the sum isnt reflecting what is expected. In April 2022, it should have cumulated value from Feb 22 to April 22.

  Is there anything I'm missing 

Conditional **bleep** =

VAR _currentValue = [LAST 4 MONTHS]

VAR _currentmonth = MAX('Date'[Month Year])

VAR _sum = SUMX(FILTER('Date', 'Date'[Month Year]<= _currentmonth), [Monthly Value])

VAR _last0Month = CALCULATE(MAX('Date'[Month Year]), FILTER('Date', 'Date'[Month Year] <= _currentmonth && _currentValue = 0))

RETURN IF(_currentValue = 0, 0,

SUMX(FILTER('Date','Date'[Month Year]>= _last0Month && 'Date'[Month Year]<=  _currentmonth),[Monthly Value]))

 

jatin__0-1654079959709.png

 

 

 

 

lbendlin
Super User
Super User

That seems not very productive.  You would have the full cumulative only for four month of the year?  What's the benefit of doing it this way?

Hi @lbendlin , Appreciate your response, in my scenario the score needs to cumulate for 9 months irrespective of the calendar year. However it also needs to reset to 0 once there's 0 score in consecutive 4 Months(including current Month) which happened in month of January 2022. 

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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