Following on from How attach actuals and forecast in a Line Chart, what I want to do now is to show the forecast but only for dates from today.
This is the code:
Forecast Engine =
SUMX(
DISTINCT('Calendar'[Date]),
VAR thisDate = 'Calendar'[Date] // Current row date
VAR y2022 = CALCULATE([Actual], FILTER(ALL('Calendar'), 'Calendar'[Date] = EDATE(thisDate, -12*3))) // 3 years ago
VAR y2023 = CALCULATE([Actual], FILTER(ALL('Calendar'), 'Calendar'[Date] = EDATE(thisDate, -12*2))) // 2 years ago
VAR y2024 = CALCULATE([Actual], FILTER(ALL('Calendar'), 'Calendar'[Date] = EDATE(thisDate, -12*1))) // 1 year ago
VAR GrowthRate1 = DIVIDE(y2023 - y2022, y2022, 0)
VAR GrowthRate2 = DIVIDE(y2024 - y2023, y2023, 0)
VAR AvgGrowthRate = (GrowthRate1 + GrowthRate2) / 2
VAR DailyForecast = y2024 * (1 + AvgGrowthRate)
VAR maxActualDate = CALCULATE(MAX('Forecast'[Costs]), ALL('Calendar'))
RETURN IF(thisDate > maxActualDate, DailyForecast)
)
How to eliminate past dates?
You can download here:
you can try to create a measure
Measure = if(max('Calendar'[Date])>=today(),1)
add this measure to visual filter and set to 1