Forum Discussion
Calculate a Running Daily Inventory
- 11 months ago
Hi,
I have solved a similar question in the attached files.
Hope this helps.
- 11 months ago
Hi jfcarter66,
Step 1: Create sample tables (Enter Data)
In Power BI Desktop, go to Home and select Enter data to create the following three tables.
Inventory
Item Date EndingInventory
A 2025-09-01 100
B 2025-09-01 50
Receipts_Wide (wide format, source of the original issue)
Item 2025-09-02 2025-09-03 2025-09-04
A 10 5 0
B 0 20 10
Usage_Wide (wide format)
Item 2025-09-02 2025-09-03 2025-09-04
A 8 12 3
B 1 2 4Step 2: Unpivot the wide tables (Power Query)
- In Power Query, select the query (e.g., Receipts_Wide).
- Select the Item column, then click Unpivot Other Columns on the Transform ribbon.
- Rename columns: Attribute → Date, Value → Quantity.
- Change the Date column type to date and Quantity to whole number.
- Rename the query to Receipts (do the same for Usage → Usage).
Step 3: Create an Items table
Items = DISTINCT(Inventory[Item])- Relate Items[Item] to Inventory[Item] (one-to-many).
- Relate Items[Item] to Receipts[Item] (one-to-many).
- Relate Items[Item] to Usage[Item] (one-to-many).
Step 4: Create Calendar Table
Dates = CALENDAR ( DATE(2025,9,1), DATE(2025,9,4) )
Calendar[Date] → Usage[Date] (many-to-one, single direction).
Calendar[Date] → Rates[Date] (many-to-one, single direction).Step 5: Create this Measure
Running Inventory =
VAR _Item = SELECTEDVALUE( Inventory[Item] )
VAR _Date = MAX( Dates[Date] )VAR _Base =
CALCULATE(
MAX( Inventory[EndingInventory] ),
FILTER( ALL( Dates ), Dates[Date] <= _Date ),
Inventory[Item] = _Item
)VAR _Receipts =
CALCULATE(
SUM( Receipts[Quantity] ),
FILTER( ALL( Receipts ), Receipts[Item] = _Item && Receipts[Date] <= _Date )
)VAR _Usage =
CALCULATE(
SUM( Usage[Quantity] ),
FILTER( ALL( Usage ), Usage[Item] = _Item && Usage[Date] <= _Date )
)RETURN
IF(
ISBLANK(_Base) && ISBLANK(_Receipts) && ISBLANK(_Usage),
BLANK(),
COALESCE(_Base,0) + COALESCE(_Receipts,0) - COALESCE(_Usage,0)
)Step 6: Test in a Table
Create a table visual with:
Dates[Date]
Inventory[Item]
The Running Inventory measureAdditionally, I have included the PBIX file that I created using the provided sample data. Kindly review it and confirm whether it aligns with your expectations.
Thank you.
I attempted to do this calculation in my dashboard. I am getting error "The SUM function only accepts a column reference as an argument.
Thoughts?