Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi guys,
I'm trying to count the number of days an item has had a stockout, this is inventory = 0. Parting from a table with transactions of items per date, I have made a running total measure that calculates the running total stock per any given day. I've also made a stockout measure, having stockout = 1 whenever the running total is 0.
What I want now is to count all days where there was a stockout, for the data given below this measure would have to be 4. This would be the equivalent of counting all days where running total was 0... any ideas on how to do this?
Thanks
| Date | TranQty In | TranQty Out | Running Total | Stockout |
| 06/06/2019 | 29 | |||
| 05/06/2019 | 29 | |||
| 04/06/2019 | 20 | 3 | 29 | |
| 03/06/2019 | 0 | 6 | 12 | |
| 02/06/2019 | 0 | 4 | 18 | |
| 01/06/2019 | 0 | 4 | 22 | |
| 31/05/2019 | 0 | 4 | 26 | |
| 30/05/2019 | 30 | 0 | 30 | |
| 29/05/2019 | 0 | 1 | ||
| 28/05/2019 | 0 | 1 | ||
| 27/05/2019 | 0 | 1 | ||
| 26/05/2019 | 0 | 2 | 0 | 1 |
| 25/05/2019 | 1 | 4 | 2 | |
| 24/05/2019 | 0 | 11 | 5 | |
| 23/05/2019 | 0 | 7 | 16 | |
| 22/05/2019 | 0 | 3 | 23 | |
| 21/05/2019 | 30 | 4 | 26 |
How about this measure:
Days Out of Stock = CALCULATE(Sum(Table1[Stockout]),Table1[Stockout]=1)
OR this measure:
Days Out = CALCULATE(count(Table1[RunningTotal]),Table1[RunningTotal]=0)
This was my initial approach, the problem is that both running total and stockout are measures... so I can't use them in the CALCULATE formula since they are not columns, i get the error "A function 'CALCULATE' has been used in a True/False expression that is used as a table filter expression. This is not allowed."
A different approach I'm exploring is having the runnning total not as a measure but as a column in my TranQty table... Presenting it as a column would solve my problem
That's what I would do if it were me. 🙂
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
Check out the November 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 59 | |
| 46 | |
| 42 | |
| 23 | |
| 18 |
| User | Count |
|---|---|
| 192 | |
| 125 | |
| 99 | |
| 67 | |
| 48 |