Forum Discussion
Inventory on hand measures
Hi,
I am looking for explanation how to, and why that way (step by step - to understand) create measure to calculate actual inventory day by day.
I would like from table that takes today's morning real inventory, and calculate day by:
After demand = Start inventory - Demand = After demand
End inventory = Start inventory - Demand + Supply = End inventory
The requested result should look like that:
| Period | Start inventory | Demand | After demand | Supply | End Inventory |
| 10.10.2022 | 800 | 100 | 700 | 100 | 800 |
| 11.10.2022 | 800 | 180 | 620 | 200 | 820 |
| 12.10.2022 | 820 | 90 | 730 | 100 | 830 |
| 13.10.2022 | 830 | 80 | 750 | 100 | 850 |
| 14.10.2022 | 850 | 170 | 680 | 200 | 880 |
| Week 42 | 880 | 880 | 0 | 1000 | 1000 |
| Week 43 | 1000 | 440 | 560 | 500 | 1060 |
My tables below:
Today inventory:
| Date | Start inventory |
| 11.10.22 | 800 |
Calendar table:
| Date | Year | Quarter | Month | Week | Weekday |
| 11.10.22 | 2022 | 4 | 10 | 41 | 2 |
| 12.10.22 | 2022 | 4 | 10 | 41 | 3 |
| 13.10.22 | 2022 | 4 | 10 | 41 | 4 |
| 14.10.22 | 2022 | 4 | 10 | 41 | 5 |
Supply table:
| Date | Supply |
| 10.10.22 | 100 |
| 11.10.22 | 200 |
| 12.10.22 | 100 |
| 13.10.22 | 100 |
| 14.10.22 | 200 |
Demand table:
| Date | Demand |
| 10.10.22 | 100 |
| 11.10.22 | 180 |
| 12.10.22 | 90 |
| 13.10.22 | 80 |
| 14.10.22 | 170 |
Actually, Today inventory table is refreshing based on Today(), so the calculactions should also start on the date given by that date.
My final idea is to see supply and demand up to the end of the next month from today date. The tables are actually refreshing like that but I shortened them to 2 and a half of the week to make it simpler.
Try
After demand = VAR StartDate = CALCULATE ( MAX ( 'Today inventory'[Date] ), ALL () ) VAR EndDate = MAX ( 'Date'[Date] ) VAR Result = CALCULATE ( SUM ( 'Today inventory'[Start inventory] ) - SUM ( Demand[Demand] ), DATESBETWEEN ( 'Date'[Date], StartDate, EndDate ) ) RETURN ResultFirst you need to get the start date from your starting inventory table, and the end date is the last date which is visible in the current filter context, so MAX('Date'[Date]) will retrieve that.
Then you just need to total up all the individual columns for all rows which fall between those 2 dates.
1 Reply
- johnt75
Super User
Try
After demand = VAR StartDate = CALCULATE ( MAX ( 'Today inventory'[Date] ), ALL () ) VAR EndDate = MAX ( 'Date'[Date] ) VAR Result = CALCULATE ( SUM ( 'Today inventory'[Start inventory] ) - SUM ( Demand[Demand] ), DATESBETWEEN ( 'Date'[Date], StartDate, EndDate ) ) RETURN ResultFirst you need to get the start date from your starting inventory table, and the end date is the last date which is visible in the current filter context, so MAX('Date'[Date]) will retrieve that.
Then you just need to total up all the individual columns for all rows which fall between those 2 dates.