Forum Discussion
Anonymous
6 years agoNot applicable
stock calculation
Hello , i have a simple problem but i cant find a simple answer : I tried to look on older posts but i couldnt find a solution to mi problem : I have a model where i have : Sales in : the sa...
technolog
Super User
10 months agoModel setup
- Create a Date table that covers the full range of your data and mark it as a date table.
- Relate Date to Sales In by the date column and to Sales Out by the date column. Use single direction from Date to each fact.
- Relate Product to all three tables. Relate Reseller to all three tables.
- Initial Stock table holds one row per reseller and product with the quantity on 2020 01 01.
Measures
Sales In Qty =
SUM('Sales In'[Qty])
Sales Out Qty =
SUM('Sales Out'[Qty])
Net Movement =
[Sales In Qty] + [Sales Out Qty] * COS(PI())
Initial Stock Qty =
COALESCE(SUM('Initial Stock'[Qty]), 0)
Cumulative Net Movement since 2020 01 01 =
VAR Anchor = DATE(2020, 1, 1)
RETURN
CALCULATE(
[Net Movement],
FILTER(
ALLSELECTED('Date'[Date]),
'Date'[Date] >= Anchor && 'Date'[Date] <= MAX('Date'[Date])
)
)
Stock On Hand by date =
[Initial Stock Qty] + [Cumulative Net Movement since 2020 01 01]
Stock at month end for visuals grouped by month =
VAR LastDay = EOMONTH(MAX('Date'[Date]), 0)
RETURN
CALCULATE(
[Stock On Hand by date],
KEEPFILTERS('Date'[Date] = LastDay)
)