Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi everyone,
I'm working on a Power BI dashboard to forecast future inventory. I have the relationships set up correctly, and I'm using the following measure to calculate the inventory forecast:
Inventory =
VAR _sum = SUM('DailyInventory_line (2)'[Total Value in EUR]) -- Current stock value
VAR _else = SUM('AFPO'[Value]) + SUM('EKPO'[Value]) - SUM('RESB'[Value]) -- Future changes from AFPO, EKPO, RESB
VAR _forecast = CALCULATE(SUM('DailyInventory_line (2)'[Total Value in EUR]), DATEADD('Date'[Date], -1, MONTH)) -- Forecast for previous month
RETURN
SWITCH(
TRUE(),
MAX('Date'[Date]) >= TODAY() && MAX('Date'[Date]) <= TODAY() + 7, _forecast + _else, -- Forecast for the next 7 days
MAX('Date'[Date]) < TODAY(), _sum -- Show current stock for past dates
)
The measure shows the changes (i.e., the sum of AFPO, EKPO, and RESB) in the graph as expected. However, I want the measure to add these future changes (_else) to the current stock value (_sum), but it’s not doing that. Instead, it seems to replace the current stock with the forecast values rather than summing them together.
The tables I am using:
AFPO (Production Orders):
EKPO (Purchase Orders):
RESB (Requirements):
DailyInventory_line (Current Inventory):
Could anyone point out why the sum of future changes isn’t being added to the current stock and how I can fix this?
Thanks in advance!
Solved! Go to Solution.
Hi 3005mfab,
The file is correct. The problem this time is since we are using TODAY() in the measure, it's looking for 8/20 in the DailyInventory table. You only have 8/19 in your sample table so the forecast worked when I looked at the report on 8/20.
Good question though. That raises one assumption in my measure. Your data must be up to date. There must be data in DailyInventory for yesterday, whenever you look at the report.
I've tweaked the measure so that it will just work off the last date where you show inventory in DailyInventory and forecast 7 days out from that date. Which version you use depends on how you want the report to work.
If you want it to be more robust to data that isn't updated (but also show incorrect data in that case, since you're using forecast data for days that will have already happened), use the newer version. If that will never be an issue or you want it to be obvious when data is not updated, the original version will work.
Updated measure is below and updated pbix is attached:
Inventory =
VAR _maxdateinventory = -- Last date with inventory
MAXX (
ALL ( DailyInventory[Date Added] ),
DailyInventory[Date Added]
)
VAR _seldate = SELECTEDVALUE ( 'Date'[Date] ) -- Selected date
VAR _sum = SUM ( 'DailyInventory'[Total Value in EUR] ) -- Current stock value
VAR _lastsum = -- Most recent actual inventory
CALCULATE (
SUM ( 'DailyInventory'[Total Value in EUR] ),
REMOVEFILTERS ( 'Date'[Date] ),
'Date'[Date] = _maxdateinventory
)
VAR _forecast = -- Future changes from AFPO, EKPO, RESB
CALCULATE (
SUM ( 'AFPO'[Value in EUR] ) + SUM ( 'EKPO'[Value in EUR] ) - SUM ( 'RESB'[Value in EUR] ),
REMOVEFILTERS ( 'Date' ),
'Date'[Date] > _maxdateinventory,
'Date'[Date] <= _seldate
)
VAR _result = -- Forecast inventory for future dates, actual for past dates
SWITCH (
TRUE(),
MAX ( 'Date'[Date] ) >= _maxdateinventory && MAX ( 'Date'[Date] ) <= _maxdateinventory + 7, _lastsum + _forecast, -- Forecast for the next 7 days
MAX ( 'Date'[Date] ) < _maxdateinventory, _sum -- Show current stock for past dates
)
RETURN _result
Proud to be a Super User! | |
Hi @Wilson_ , attached the file! https://we.tl/t-RTAl1SjG8W
The projection logic should work as follows:
Here’s how you can implement this logic in Power BI:
Start with the current Total Value in EUR: Use the Daily Inventory table to retrieve the value for Date Added = 8/19/2024. This will be the starting point for the forecast.
Calculate projected values for the following days:
For each future date, the calculation would be
Projected Value (for day N) = Total Value (previous day)
+ SUM(EKPO[Value] for day N)
+ SUM(AFPO[Value] for day N)
- SUM(RESB[Value] for day N)
3005mfab,
See attached pbix (image below).
The biggest issue in your original measure is there was no cumulative sum as you continue to go into future dates. Let me know if you have any questions about my updated measure.
Proud to be a Super User! | |
Hi @Wilson_ , thanks for your help! But did you perhaps send me the wrong file, because unfortunately the same problem persists. Because unfortunately your image is correct, but the file you attached is different. The problem is still that only the changes are displayed. I would be very grateful if you could help me with this again!
Hi 3005mfab,
The file is correct. The problem this time is since we are using TODAY() in the measure, it's looking for 8/20 in the DailyInventory table. You only have 8/19 in your sample table so the forecast worked when I looked at the report on 8/20.
Good question though. That raises one assumption in my measure. Your data must be up to date. There must be data in DailyInventory for yesterday, whenever you look at the report.
I've tweaked the measure so that it will just work off the last date where you show inventory in DailyInventory and forecast 7 days out from that date. Which version you use depends on how you want the report to work.
If you want it to be more robust to data that isn't updated (but also show incorrect data in that case, since you're using forecast data for days that will have already happened), use the newer version. If that will never be an issue or you want it to be obvious when data is not updated, the original version will work.
Updated measure is below and updated pbix is attached:
Inventory =
VAR _maxdateinventory = -- Last date with inventory
MAXX (
ALL ( DailyInventory[Date Added] ),
DailyInventory[Date Added]
)
VAR _seldate = SELECTEDVALUE ( 'Date'[Date] ) -- Selected date
VAR _sum = SUM ( 'DailyInventory'[Total Value in EUR] ) -- Current stock value
VAR _lastsum = -- Most recent actual inventory
CALCULATE (
SUM ( 'DailyInventory'[Total Value in EUR] ),
REMOVEFILTERS ( 'Date'[Date] ),
'Date'[Date] = _maxdateinventory
)
VAR _forecast = -- Future changes from AFPO, EKPO, RESB
CALCULATE (
SUM ( 'AFPO'[Value in EUR] ) + SUM ( 'EKPO'[Value in EUR] ) - SUM ( 'RESB'[Value in EUR] ),
REMOVEFILTERS ( 'Date' ),
'Date'[Date] > _maxdateinventory,
'Date'[Date] <= _seldate
)
VAR _result = -- Forecast inventory for future dates, actual for past dates
SWITCH (
TRUE(),
MAX ( 'Date'[Date] ) >= _maxdateinventory && MAX ( 'Date'[Date] ) <= _maxdateinventory + 7, _lastsum + _forecast, -- Forecast for the next 7 days
MAX ( 'Date'[Date] ) < _maxdateinventory, _sum -- Show current stock for past dates
)
RETURN _result
Proud to be a Super User! | |
Hi 3005mfab,
Can you please share a sample pbix file? (If you don't know how, please check the pinned thread in the forum.) It would make debugging your issue easier. 🙂
Proud to be a Super User! | |
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
79 | |
78 | |
59 | |
36 | |
33 |
User | Count |
---|---|
93 | |
59 | |
56 | |
49 | |
41 |