Forum Discussion
Running Sum with Stacked Area chart ?
- 1 year ago
Hey Cookistador ,
I suggest this measure that is more simple and probably a little faster:
SalesAmount (running) = var currentdDateKey = CALCULATE( MAX( 'DimDate'[Datekey] ) ) return IF( NOT( ISBLANK( [SalesAmount (ms)] ) ), CALCULATE( [SalesAmount (ms)] , 'DimDate'[Datekey] <= currentdDateKey ), BLANK() )Of course, it's the same approach (i call this approach "sanity check"), checking if he current date (being pecised the max value based on the datekey granularity) has a value if not, do not create a running sum. This will avoid the "unnecessary calculations" while doing a "running something":
But then, you have to be prepared that your chart will look like this:
This happens because a line is not "projected" when there is no value. for this reason, you probably have to adapt the "sanity check" and the grain of your x-axis.
Hopefully, this helps to tackle your challenge.Regards,
Tom
Hi Cookistador -Instead of using your full date table, which results in calculations for each day, restrict the calculation to dates with non-blank values for AverageValue.
create a below running sum measure:
VAR CurrentDate = MAX('Date'[Date])
VAR RunningSum =
CALCULATE(
SUMX(
FILTER(
ALLSELECTED('Date'[Date]),
'Date'[Date] <= CurrentDate &&
NOT(ISBLANK([AverageValue])) -- Only include dates with non-blank values
),
[AverageValue]
)
)
RETURN
IF(RunningSum <= 0, BLANK(), RunningSum)
To further improve performance, you can limit the calculation to a rolling window (e.g., the last 12 months) if a cumulative view of all historical data isn’t necessary. You can apply this condition in the FILTER section of your measure to restrict the calculation to the most recent dates.