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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply

cumulative running sum

Dear experts,

I would like to ask solutions to create a column which summarizes cumulatively value in column "Total" based on column "Date", in 3-day period, for example:

Cumulative sum of "Total" by Date 24/06 = sum of total from date 22/06 to date 24/06

Cumulative sumof Total by Date 23/06 = sum of total from date 21/06 to date 23/06

 

DateIdTotal
20/06/2016111
20/06/2016172
20/06/2016264
21/06/20161795
21/06/20161837
21/06/20161848
21/06/201629856
22/06/2016102558
22/06/2016102859
22/06/2016103061
22/06/20162624211
22/06/20162682212
22/06/20162752214
22/06/20162772215
23/06/201611217
23/06/201617218
23/06/201628220
23/06/201631221
24/06/2016218662
24/06/2016220664
24/06/2016221665
24/06/2016222667
24/06/2016224668
24/06/2016231670
24/06/2016240671
24/06/2016243673
24/06/2016250674
24/06/2016251676
24/06/2016264677
24/06/2016268679
24/06/2016269680
24/06/2016276682
24/06/2016278683
24/06/2016280685
24/06/2016293686
24/06/2016294688
24/06/2016298689
24/06/2016299691
24/06/2016306692
24/06/2016312694
24/06/2016313695
24/06/20161013697
24/06/20161018698
24/06/20161021700
24/06/20161023701
24/06/20161028703
24/06/20161030704
24/06/20161031706
24/06/20161032707
24/06/20161033709
24/06/20161050710
24/06/20161053712
24/06/20161055713
24/06/20161059715
24/06/20161068716
24/06/20161074718
24/06/20161076719
24/06/20161082721
24/06/20161083722
24/06/20161102724
24/06/20161106725
24/06/20161107727
24/06/20161110728
24/06/20161141730
24/06/20161143731
24/06/20161145733
24/06/20161151734
24/06/20161152736
24/06/20161153737
24/06/20161154739
24/06/20161156740
24/06/20161158742
24/06/20161159743
24/06/20161162745
24/06/20161163746
24/06/20161166748
24/06/20161167749
24/06/20161170751
24/06/20161179752
24/06/20161180754
24/06/20161184755
24/06/20161185757
24/06/20161186758
24/06/20161190760
24/06/20161193761
24/06/20161199763
24/06/20161200764
24/06/20161201766
24/06/20161204767
24/06/20161212769
24/06/20161220770
24/06/20161227772
24/06/20161229773
24/06/20161238775
24/06/20161245776
24/06/20161246778
24/06/20161260779
24/06/20161261781
24/06/20161262782
24/06/20161264784
24/06/20161266785
24/06/20161271787
24/06/20161272788
24/06/20161273790
24/06/20161274791
24/06/20161276793
24/06/20161287794
24/06/20161288796
24/06/20161291797


Thanks in advance for your help! 

1 ACCEPTED SOLUTION
jahida
Impactful Individual
Impactful Individual

@KGrice 's solution will work for sure, seems a bit of overkill to have 3 filter clauses for this though. Here's a compressed alternative with the same result:

 

MovingSum = CALCULATE(SUM(Table2[Total]),
		FILTER(ALLEXCEPT(Table2, Table2[Id]), Table2[Date] > MAX(Table2[Date])-2 && Table2[Date] <= MAX(Table2[Date])))

View solution in original post

6 REPLIES 6
KGrice
Memorable Member
Memorable Member

Hi @BusinessAnalyst. Try this out:

 

MovingSum = CALCULATE(SUM(TableName[Total]), FILTER(ALL(TableName), TableName[Date] > MAX(TableName[Date])-2), FILTER(ALL(TableName), TableName[Date] <= MAX(TableName[Date])))

 

Many thanks for your insight. It worked! I would like to ask if the calculation also based on ID, for example:

 

Cumulative sum of ID 11 by date 22/06 = total[ID11 in date 20/06] + total[ID11 in date 21/06] + total [ID11 in date 22/06]

(without including other ID like ID17, ID26, etc in date 20/06)

 

DateIdTotal 
20/06/2016111 
20/06/2016172 
20/06/2016264 
21/06/20161795 
21/06/2016117 
21/06/20161848 
21/06/201629856 
22/06/2016102558 
22/06/20161159 =1+7+59
22/06/2016103061 
22/06/20162624211 
22/06/20162682212 
22/06/20162752214 
22/06/20162772215 
23/06/201611217 
23/06/201617218 
23/06/201628220 

 

I am grateful very much for your help!

 

Best regards,

Glad to help! You can extend the previous measure to include the Id by adding another filter, like so:

 

MovingSumByID = CALCULATE(SUM(TableName[Total]), 
FILTER(ALL(TableName), TableName[Date] > MAX(TableName[Date])-2),
FILTER(ALL(TableName), TableName[Date] <= MAX(TableName[Date])),
FILTER(ALL(TableName), TableName[Id]=MAX(TableName[Id]))
)
jahida
Impactful Individual
Impactful Individual

@KGrice 's solution will work for sure, seems a bit of overkill to have 3 filter clauses for this though. Here's a compressed alternative with the same result:

 

MovingSum = CALCULATE(SUM(Table2[Total]),
		FILTER(ALLEXCEPT(Table2, Table2[Id]), Table2[Date] > MAX(Table2[Date])-2 && Table2[Date] <= MAX(Table2[Date])))

Dear experts,

 

I tried both and see that:

@KGrice's solution return to the same value in each row.

 

And @jahida's solution (MovingSum) doesn't return to desired result.

 

My wish is as below:

Date  Id  Total  Desired resultExplanation of Result
20/06/2016  11  1  1sum total {(ID11, date 20/6) + (ID11, date 19/6) + (ID11, date 18/06)}. The result should be = 1 + 0 + 0 = 1, because there is no data of date 19/06 and date 18/06
20/06/2016  17  2  2 
20/06/2016  26  4  4 
21/06/2016  179  5  5 
21/06/2016  183  7  7 
21/06/2016  11  8  9sum total {(ID11, date 21/6) + (ID11, date 20/6) + (ID11, date 19/06)}. The result should be = 8 + 1 + 0 = 9, because there is no date of date 19/06
21/06/2016  298  56  56Result here = 56 = 56 + 0 + 0 because there is only data in date 21/06 (=56) no other date of ID298 in 20/06 and 19/06
22/06/2016  1025  58  58 
22/06/2016  1028  59  59 
22/06/2016  11  61  70sum total {(ID11, date 22/6) + (ID11, date 21/6) + (ID11, date 20/06)}. The result should be = 61 + 8 + 1 = 70
22/06/2016  2624  211  211 
22/06/2016  2682  212  212 


 
Hope it can be solved! Many thanks to your great contribution! 

Cheers!

 

@BusinessAnalyst

 

Hi I Try the Jahida's dax with your sample data and it Works.

 

Is the same value total and moving sum because your sample data don't have id with 3 consecutive days. I just modified the data with one row for ID 11 in 22/06/16 to test it.

DE.png

 

 

 

 




Lima - Peru

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.