Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
alexvc
Resolver I
Resolver I

Days with stockout - Conditional count from a running total measure per day

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

 

DateTranQty InTranQty OutRunning TotalStockout
06/06/2019  29 
05/06/2019  29 
04/06/201920329 
03/06/20190612 
02/06/20190418 
01/06/20190422 
31/05/20190426 
30/05/201930030 
29/05/2019  01
28/05/2019  01
27/05/2019  01
26/05/20190201
25/05/2019142 
24/05/20190115 
23/05/20190716 
22/05/20190323 
21/05/201930426 
3 REPLIES 3
JoyCornerstone
Resolver II
Resolver II

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. 🙂

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.