Forum Discussion
Amount of $ in inventory over time
- Jul 24, 2023
If something like this
one of variants could be
- load source table to data model, by Power Query in that sample
- in Power Pivot or by Power Query (lot of templates exist) add Date (aka Calendar) table to data model
- create relationships with source table
(only one of them will be shown as active)
- create DAX measures
Cost Amount:=SUM ( Query_Table1[Total Cost] ) Cost Delivered:=VAR lastInPeriod = MAX ( 'Calendar'[Date] ) VAR firstInPeriod = MIN ( 'Calendar'[Date] ) VAR lastDelivered = CALCULATE ( MAX ( Query_Table1[Date delivered to Warehouse] ), ALL ( Query_Table1 ) ) VAR lastSold = CALCULATE ( MAX ( Query_Table1[Date Sold (out of warehouse)] ), ALL ( Query_Table1 ) ) VAR lastInventory = MAX ( lastDelivered, lastSold ) VAR result = IF ( firstInPeriod <= lastInventory, CALCULATE ( [Cost Amount], 'Calendar'[Date] <= lastInPeriod, Query_Table1[Date delivered to Warehouse] <> BLANK (), USERELATIONSHIP ( 'Calendar'[Date], Query_Table1[Date delivered to Warehouse] ) ) ) RETURN result Cost Sold:=VAR lastInPeriod = MAX ( 'Calendar'[Date] ) VAR firstInPeriod = MIN ( 'Calendar'[Date] ) VAR lastDelivered = CALCULATE ( MAX ( Query_Table1[Date delivered to Warehouse] ), ALL ( Query_Table1 ) ) VAR lastSold = CALCULATE ( MAX ( Query_Table1[Date Sold (out of warehouse)] ), ALL ( Query_Table1 ) ) VAR lastInventory = MAX ( lastDelivered, lastSold ) VAR result = IF ( firstInPeriod <= lastInventory, CALCULATE ( [Cost Amount], 'Calendar'[Date] <= lastInPeriod, Query_Table1[Date Sold (out of warehouse)] <> BLANK (), USERELATIONSHIP ( 'Calendar'[Date], Query_Table1[Date Sold (out of warehouse)] ) ) ) RETURN result Inventory Amount:=[Cost Delivered] - [Cost Sold]- use above to build PivotTable and/or PivotChart from data model.
Please check in attached file.
If something like this
one of variants could be
- load source table to data model, by Power Query in that sample
- in Power Pivot or by Power Query (lot of templates exist) add Date (aka Calendar) table to data model
- create relationships with source table
(only one of them will be shown as active)
- create DAX measures
Cost Amount:=SUM ( Query_Table1[Total Cost] )
Cost Delivered:=VAR lastInPeriod =
MAX ( 'Calendar'[Date] )
VAR firstInPeriod =
MIN ( 'Calendar'[Date] )
VAR lastDelivered =
CALCULATE (
MAX ( Query_Table1[Date delivered to Warehouse] ),
ALL ( Query_Table1 )
)
VAR lastSold =
CALCULATE (
MAX ( Query_Table1[Date Sold (out of warehouse)] ),
ALL ( Query_Table1 )
)
VAR lastInventory =
MAX ( lastDelivered, lastSold )
VAR result =
IF (
firstInPeriod <= lastInventory,
CALCULATE (
[Cost Amount],
'Calendar'[Date] <= lastInPeriod,
Query_Table1[Date delivered to Warehouse] <> BLANK (),
USERELATIONSHIP ( 'Calendar'[Date], Query_Table1[Date delivered to Warehouse] )
)
)
RETURN
result
Cost Sold:=VAR lastInPeriod =
MAX ( 'Calendar'[Date] )
VAR firstInPeriod =
MIN ( 'Calendar'[Date] )
VAR lastDelivered =
CALCULATE (
MAX ( Query_Table1[Date delivered to Warehouse] ),
ALL ( Query_Table1 )
)
VAR lastSold =
CALCULATE (
MAX ( Query_Table1[Date Sold (out of warehouse)] ),
ALL ( Query_Table1 )
)
VAR lastInventory =
MAX ( lastDelivered, lastSold )
VAR result =
IF (
firstInPeriod <= lastInventory,
CALCULATE (
[Cost Amount],
'Calendar'[Date] <= lastInPeriod,
Query_Table1[Date Sold (out of warehouse)] <> BLANK (),
USERELATIONSHIP ( 'Calendar'[Date], Query_Table1[Date Sold (out of warehouse)] )
)
)
RETURN
result
Inventory Amount:=[Cost Delivered] - [Cost Sold]
- use above to build PivotTable and/or PivotChart from data model.
Please check in attached file.