Forum Discussion
NR5046
6 years agoRegular Visitor
Cumulative Sum with Restricted Dates
Hello! I am having an issue with my cumulative sum formula. I just created a universal date table to connect and filter all of my other tables. The dates range 200 years. I now am trying to creat...
Anonymous
6 years agoNot applicable
To use ALLSELECTED you have to know how it works. Throwing functions (semi-randomly) at a formula without a deep understanding of how a function works is a sure way to fail.
Try this code:
[Cumul Sum] =
var __lastVisibleDate = MAX( CostTable[Date] )
return
CALCULATE(
SUM( CostTable[ColumnToSumOver] ),
CostTable[Date] <= __lastVisibleDate
ALL( DateTable )
)
// Here's a different version
// that will give you the correct VISUAL
// cumulative but only if the dates
// visible are consecutive.
[Cumul Sum] =
var __lastVisibleDate = MAX( CostTable[Date] )
var __firstVisibleDate =
CALCULATE(
MIN( CostTable[Date] ),
ALLSELECTED( DateTable )
)
return
CALCULATE(
SUM( CostTable[ColumnToSumOver] ),
CostTable[Date] <= __lastVisibleDate,
__firstVisibleDate <= CostTable[Date],
ALL( DateTable )
)
// And this version will give you
// the correct visual cumulative
// even for non-contiguous dates.
[Cumul Sum] =
var __lastVisibleDate = MAX( DateTable[Date] )
return
CALCULATE(
SUM( CostTable[ColumnToSumOver] ),
KEEPFILTERS(
DateTable[Date] <= __lastVisibleDate
),
ALLSELECTED( DateTable )
)