Forum Discussion
Calculate forecast based on increase and previous calculated month result
- 4 years ago
Try these measures. I made the Period column a date by adding the first day of the month (2022-01 becomes 2022-01-01). This will enable you to create a relationship with the date table. Alternatively, you could create a Period Number column with values like 202201, and use Period Number instead of Period in the Running Total measure.
Actual = SUM ( FactTable[Actual] )Forecast = SUM ( FactTable[Forecast] )Running Total = VAR vLastActual = CALCULATE ( LASTNONBLANKVALUE ( FactTable[Actual], [Actual] ), ALLSELECTED ( FactTable ) ) VAR vResult = IF ( MAX ( FactTable[Actual] ) <> BLANK (), [Actual], vLastActual + CALCULATE ( [Forecast], FILTER ( ALLSELECTED ( FactTable ), FactTable[Period] <= MAX ( FactTable[Period] ) ) ) ) RETURN vResult - 4 years ago
Try this measure. I adjusted the DAX to handle months where both Actual and Forecast exist.
Running Total = VAR vLastActual = CALCULATE ( LASTNONBLANKVALUE ( Actual[Actual Value], [ActualValue] ), ALLSELECTED ( Actual ) ) VAR vLastActualDate = CALCULATE ( LASTNONBLANK ( 'Date'[Date], [ActualValue] ), ALLSELECTED ( Actual ) ) VAR vResult = IF ( MAX ( Actual[Actual Value] ) <> BLANK (), [ActualValue], vLastActual + CALCULATE ( [ForecastValue], FILTER ( ALLSELECTED ( 'Date' ), 'Date'[Date] <= MAX ( 'Date'[Date] ) && 'Date'[Date] > vLastActualDate ) ) ) RETURN vResultNow you can take that vacation. 🙂
Try these measures. I made the Period column a date by adding the first day of the month (2022-01 becomes 2022-01-01). This will enable you to create a relationship with the date table. Alternatively, you could create a Period Number column with values like 202201, and use Period Number instead of Period in the Running Total measure.
Actual = SUM ( FactTable[Actual] )Forecast = SUM ( FactTable[Forecast] )Running Total =
VAR vLastActual =
CALCULATE (
LASTNONBLANKVALUE ( FactTable[Actual], [Actual] ),
ALLSELECTED ( FactTable )
)
VAR vResult =
IF (
MAX ( FactTable[Actual] ) <> BLANK (),
[Actual],
vLastActual
+ CALCULATE (
[Forecast],
FILTER (
ALLSELECTED ( FactTable ),
FactTable[Period] <= MAX ( FactTable[Period] )
)
)
)
RETURN
vResult
DataInsights
Worked like a charm. Thank you.
One question. If e.g. 2022-11 is a blank / null value and not zero in the forecast.
How can I obtain the same result, mening 2022-11 = 4053.
- DataInsights4 years ago
Super User
Glad to hear that worked. I changed the 2022-11 forecast to blank/null and got the same result. Are you getting a different result?