I have four tables: Daily Inventory, AFPO, RESB, and EKPO.
Daily inventory:
Material ID | Date Added | Total Value |
---|---|---|
1 | 08/19/2024 | 50 |
2 | 08/19/2024 | 100 |
3 | 08/19/2024 | 1000 |
AFPO and EKPO have the same headers and data, they are both incoming materials which will increase inventory value:
AFPO/EKPO:
Material ID | Delivery Date | Value Added |
---|---|---|
1 | 08/19/2024 | 50 |
2 | 08/20/2024 | 100 |
3 | 08/21/2024 | 1000 |
1 | 08/20/2024 | 55 |
3 | 08/24/2024 | 500 |
RESB is the table with requirements with the same headers as AFPO but the value needs to be subtracted from the Daily Inventory total value.
I am trying to create a measure within “Date” table (it is connected to AFPO, EKPO, RESB, and Daily Inventory via Date column) which has one column “Date” starting from current day. The measure should provide how the “Total Value” from Daily Inventory will change over the next 7 days.
Here is the measure I have tried which almost provides the desired result:
Inventory Forecast =
VAR _today = TODAY()
VAR _sum =
SUM ( 'DailyInventory'[Total Value])
VAR _else =
SUM ( 'AFPO'[Value] ) + SUM ( 'EKPO'[Value] )
- SUM ( 'RESB'[Value] )
-- Forecast for today's date
VAR _forecast_today =
CALCULATE (
SUM ( 'DailyInventory'[Total Value] ),
'Date'[Date] = _today
)
-- Forecast for the next 7 days
VAR _forecast_7_days =
CALCULATE (
SUM ( 'DailyInventory'[Total Value]),
DATESINPERIOD ( 'Date'[Date], _today, 7, DAY )
)
RETURN
SWITCH (
TRUE(),
MAX ( 'Date'[Date] ) = _today, _forecast_today + _else,
MAX ( 'Date'[Date] ) > _today && MAX ( 'Date'[Date] ) <= _today + 7, _forecast_7_days + _else,
_sum
)
The issue with this measure is that for every next day, it takes current day’s (08/19/2024) “Daily Inventory” total value rather than taking previous day Total value after EKPO, AFPO, and RESB summation.
While this measure would work for the first day 8/19/2024, for other dates it will not.
For example: For 08/21/2024, it will use 08/19/2024 Total value and subtract the requirements from 8/21/2024 instead of taking value of 08/20/2024 after all the summation.
I would appreciate any help.