I am trying to count the number of "days in stock" for each product in the inventory. As a source of data, I have a dedicated Calendar table and a Stock Movement table containing records only for the days when movement actually occurred (not every day). There is a relationship between the tables.
With the code below I attempted to make a "left join" alternative in DAX and count the rows after. The result is meaningless.
I need to get the number of days where QTY > 0
from the beginning of the year including days with no movement. A "Calculate" is included for transferring the row context (Model, Branch,...) to the measure.
days in stock =
VAR StockPerDay =
ADDCOLUMNS (
'Calendar';
"DailyQty"; CALCULATE (
SUM ( StockMovement[qty] );
StockMovement[Date] <= EARLIER ( 'Calendar'[Date] )
)
)
RETURN
COUNTROWS ( FILTER ( StockPerDay; [DailyQty] > 0 ) )
The data in Stock Movement table looks like the following:
I am new to DAX so any help will be much appreciated.
StockMovement
table looks like? – Alexis Olson