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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
jps_HHH
Helper II
Helper II

Accumulate sum

Hi all,

 

I've a database that it is a list of several costs.  Some lines are related to budget items and other lines are the atual costs debited. 

(there is a column with BGD if it is an item related to budget or ACT if it is a cost that was debited). 

 

I created a new measure to calculate the accumulated sum using this formula:

**bleep** Atual  =
VAR _maxdate = MAX('Cost Production Lines'[Month])
RETURN
CALCULATE(sum('Cost Production Lines'[Val.in rep.cur.]),ALLSELECTED('Cost Production Lines'),'Cost Production Lines'[Month]<= _maxdate)

 

And I created a visual (line graph) to show the accumulated costs over the months. To avoid to show "budeget" items, I filtered the visual to not show BDG items). 

However, I would like to add a new line showing the accumulated budget over the months too. Is it that possible? 

 

1 ACCEPTED SOLUTION

Hi @jps_HHH ,
here's an example of how to calculate a forecast assuming a percentage growth:

ForecastActualCosts =
VAR _maxActualDate = CALCULATE(
    MAX('Cost Production Lines'[Month]),
    'Cost Production Lines'[Type] = "ACT"
)
VAR _futureMonths = SELECTCOLUMNS(
    FILTER(
        ALL('Cost Production Lines'[Month]),
        'Cost Production Lines'[Month] > _maxActualDate
    ),
    "Month", [Month]
)
VAR _forecastValue = 1.05 -- Example: 5% monthly growth
RETURN
SUMX(
    _futureMonths,
    CALCULATE(
        SUM('Cost Production Lines'[Val.in rep.cur.]) * _forecastValue,
        'Cost Production Lines'[Month] <= _maxActualDate
    )
)

 

Modify _forecastValue or replace the growth logic with your specific forecast method.

 

Now you can combine Actual and Forecast Lines:

CombinedActualAndForecast =
VAR _maxdate = MAX('Cost Production Lines'[Month])
VAR _actualMaxDate = CALCULATE(
    MAX('Cost Production Lines'[Month]),
    'Cost Production Lines'[Type] = "ACT"
)
RETURN
IF(
    _maxdate <= _actualMaxDate,
    CALCULATE(
        SUM('Cost Production Lines'[Val.in rep.cur.]),
        ALLSELECTED('Cost Production Lines'),
        'Cost Production Lines'[Month] <= _maxdate,
        'Cost Production Lines'[Type] = "ACT"
    ),
    ForecastActualCosts
)

 

 

View solution in original post

4 REPLIES 4
Laxmanjatoth
Resolver I
Resolver I

Accumulated Budget =
VAR _maxdate = MAX(date)
RETURN
CALCULATE(
SUM('Cost Production Lines'[Val.in rep.cur.]),
ALLSELECTED('Cost Production Lines'),
'Cost Production Lines'[Month] <= _maxdate,
'Cost Production Lines'[Type] = "BGD"
)

Bibiano_Geraldo
Super User
Super User

Hi @jps_HHH ,
You already have this measure, but ensure it filters only for ACT:

AccumulatedActualCosts =
VAR _maxdate = MAX('Cost Production Lines'[Month])
RETURN
CALCULATE(
    SUM('Cost Production Lines'[Val.in rep.cur.]),
    ALLSELECTED('Cost Production Lines'),
    'Cost Production Lines'[Month] <= _maxdate,
    'Cost Production Lines'[Type] = "ACT"
)

 

Now create a similar measure but filter for BDG:

AccumulatedBudgetCosts =
VAR _maxdate = MAX('Cost Production Lines'[Month])
RETURN
CALCULATE(
    SUM('Cost Production Lines'[Val.in rep.cur.]),
    ALLSELECTED('Cost Production Lines'),
    'Cost Production Lines'[Month] <= _maxdate,
    'Cost Production Lines'[Type] = "BDG"
)

 

Add Month to the X-axis.
Add both AccumulatedActualCosts and AccumulatedBudgetCosts to the Values field of the line chart.
This will create two separate lines: one for the actual costs and one for the budget costs.

If your data model allows, you can use a Type column (ACT/BDG) as a legend. This will automatically split the lines by type, but only if you don't need separate measures.

It works. 

But the "actual line" should stop at November and not maintain the same values for future months. And I would also like to include a forecast for "actual line" . If it will overlap the budget line in March 2025 or not. Capture.PNG

Hi @jps_HHH ,
here's an example of how to calculate a forecast assuming a percentage growth:

ForecastActualCosts =
VAR _maxActualDate = CALCULATE(
    MAX('Cost Production Lines'[Month]),
    'Cost Production Lines'[Type] = "ACT"
)
VAR _futureMonths = SELECTCOLUMNS(
    FILTER(
        ALL('Cost Production Lines'[Month]),
        'Cost Production Lines'[Month] > _maxActualDate
    ),
    "Month", [Month]
)
VAR _forecastValue = 1.05 -- Example: 5% monthly growth
RETURN
SUMX(
    _futureMonths,
    CALCULATE(
        SUM('Cost Production Lines'[Val.in rep.cur.]) * _forecastValue,
        'Cost Production Lines'[Month] <= _maxActualDate
    )
)

 

Modify _forecastValue or replace the growth logic with your specific forecast method.

 

Now you can combine Actual and Forecast Lines:

CombinedActualAndForecast =
VAR _maxdate = MAX('Cost Production Lines'[Month])
VAR _actualMaxDate = CALCULATE(
    MAX('Cost Production Lines'[Month]),
    'Cost Production Lines'[Type] = "ACT"
)
RETURN
IF(
    _maxdate <= _actualMaxDate,
    CALCULATE(
        SUM('Cost Production Lines'[Val.in rep.cur.]),
        ALLSELECTED('Cost Production Lines'),
        'Cost Production Lines'[Month] <= _maxdate,
        'Cost Production Lines'[Type] = "ACT"
    ),
    ForecastActualCosts
)

 

 

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.