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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
ashton99
Regular Visitor

Forecasting Dax help

I've been trying to do this for a while and just cant figure it out. Im trying to "forecast" StartingBalance using palletsfromcontainers and palletsshipped. in excel it would be quite simple but i need it to update itself.

In excel it would be Starting balance + Pallets from containers - Pallets Shipped. The next row would then start with the final value from that and be Forecasted balance (from previous row) + Pallets from containers - Pallets Shipped.

 

This is what my dataset table looks like:

ashton99_0-1722252622159.png

 

thanks

1 ACCEPTED SOLUTION
SamWiseOwl
Super User
Super User

Hi @ashton99 
In this specific scenario could you do Starting value + all prior (Received - Dispatched).

SamWiseOwl_0-1722257381591.png

The DAX is:

Forecast stock =
var firstvalue = maxx(TOPN(1,'Test Table','Test Table'[Date],ASC),[Starting Balance])
--Capture the first Starting balance in the data
var currDate = [Date] --Capture the current date
RETURN
firstvalue + --Add the starting value
SUMX( --Calculate the total of all Pallets received less pallets shipped
    FILTER('Test Table', [Date] <= currDate) --Only include rows on or before current row
    ,[Pallets From Containers] - [Pallets Shipped] --subtract shipped from returned
)
There is a function called OFFSET() and another call ONORBEFORE() which might do what you are thinking.
There is also the possible answer using EARLIER, I wrote a blog about forecast calcuations here.
Let me know if the above isn't doing what you would like.

If it is please mark this as a solution for others to find 🙂

If you are happy with this answer please mark as a solution for others to find !

Kudos are always appreciated! Check out our free Power BI video courses.

View solution in original post

1 REPLY 1
SamWiseOwl
Super User
Super User

Hi @ashton99 
In this specific scenario could you do Starting value + all prior (Received - Dispatched).

SamWiseOwl_0-1722257381591.png

The DAX is:

Forecast stock =
var firstvalue = maxx(TOPN(1,'Test Table','Test Table'[Date],ASC),[Starting Balance])
--Capture the first Starting balance in the data
var currDate = [Date] --Capture the current date
RETURN
firstvalue + --Add the starting value
SUMX( --Calculate the total of all Pallets received less pallets shipped
    FILTER('Test Table', [Date] <= currDate) --Only include rows on or before current row
    ,[Pallets From Containers] - [Pallets Shipped] --subtract shipped from returned
)
There is a function called OFFSET() and another call ONORBEFORE() which might do what you are thinking.
There is also the possible answer using EARLIER, I wrote a blog about forecast calcuations here.
Let me know if the above isn't doing what you would like.

If it is please mark this as a solution for others to find 🙂

If you are happy with this answer please mark as a solution for others to find !

Kudos are always appreciated! Check out our free Power BI video courses.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.