Forum Discussion
HELP WITH A MEASURE: First Date Running Total is 0
- 1 year ago
First, create the measures for cumulative quantities:
Qty Purchase = SUM('Purchase Table'[Qty purchase])Qty Inbound = SUM('Inbound Table'[Quantity Inbound])
**bleep** Qty Purchase = CALCULATE([Qty Purchase], FILTER(ALL('Date Table'), 'Date Table'[Date] <= MAX('Date Table'[Date])))
**bleep** Qty Inbound = CALCULATE([Qty Inbound], FILTER(ALL('Date Table'), 'Date Table'[Date] <= MAX('Date Table'[Date])))
Create the measure for the actual stock:
Actual Stock = [**bleep** Qty Inbound] - [**bleep** Qty Purchase]
Create the measure to find the first date where the actual stock is 0:
First Date 0 Stock =
CALCULATE(
MIN('Date Table'[Date]),
FILTER(
ALL('Date Table'),
[Actual Stock] = 0
)
)
This measure will return the first date where the actual stock is 0 by iterating over all dates and checking the condition.If you need to ensure that the date is after the first purchase date, you can modify the measure to include that condition:
First Date 0 Stock =
VAR FirstPurchaseDate = CALCULATE(MIN('Date Table'[Date]), FILTER(ALL('Date Table'), [Qty Purchase] > 0))
RETURN
CALCULATE(
MIN('Date Table'[Date]),
FILTER(
ALL('Date Table'),
[Actual Stock] = 0 && 'Date Table'[Date] >= FirstPurchaseDateThis measure first calculates the first purchase date and then finds the first date where the actual stock is 0 and the date is on or after the first purchase date.
First, create the measures for cumulative quantities:
Qty Purchase = SUM('Purchase Table'[Qty purchase])
Qty Inbound = SUM('Inbound Table'[Quantity Inbound])
**bleep** Qty Purchase = CALCULATE([Qty Purchase], FILTER(ALL('Date Table'), 'Date Table'[Date] <= MAX('Date Table'[Date])))
**bleep** Qty Inbound = CALCULATE([Qty Inbound], FILTER(ALL('Date Table'), 'Date Table'[Date] <= MAX('Date Table'[Date])))
Create the measure for the actual stock:
Actual Stock = [**bleep** Qty Inbound] - [**bleep** Qty Purchase]
Create the measure to find the first date where the actual stock is 0:
First Date 0 Stock =
CALCULATE(
MIN('Date Table'[Date]),
FILTER(
ALL('Date Table'),
[Actual Stock] = 0
)
)
This measure will return the first date where the actual stock is 0 by iterating over all dates and checking the condition.
If you need to ensure that the date is after the first purchase date, you can modify the measure to include that condition:
First Date 0 Stock =
VAR FirstPurchaseDate = CALCULATE(MIN('Date Table'[Date]), FILTER(ALL('Date Table'), [Qty Purchase] > 0))
RETURN
CALCULATE(
MIN('Date Table'[Date]),
FILTER(
ALL('Date Table'),
[Actual Stock] = 0 && 'Date Table'[Date] >= FirstPurchaseDate
This measure first calculates the first purchase date and then finds the first date where the actual stock is 0 and the date is on or after the first purchase date.