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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
SIA3720
Frequent Visitor

Count number of days at 0 balance

Hi,

 

I have a table listing he running balance of stock items. Over 1000 items. A new line is added to the table whenever there is movement in the stock quantity i.e. when the stock increases or decreases. There is not a movement for every item everyday. 

 

This means that if an item reaches a 0 balance, a new line will not appear until the next time the stock is replenished. 

 

The issue I have is I need to calculate the % stock out rate per month.

 

I toyed with the idea of filling in all the missing dates between movements and filling down the balances but found this super slow, although I have done it to get a closing monthly balance per item.

 

Sample data:

DateItemRunning_stock_balance
01/09/2023A150
01/09/2023C14
02/09/2023A110
03/09/2023B43
04/09/2023A65
05/09/2023A40
07/09/2023A0
08/09/2023B0
10/09/2023A200
10/09/2023C13
14/09/2023A180
15/09/2023A150
15/09/2023C12
17/09/2023A140
18/09/2023A130
21/09/2023B100
23/09/2023A110
26/09/2023B96
28/09/2023B95
29/09/2023C17
30/09/2023A100
30/09/2023C16

 

Required Output: (Sum of number of items per day that had a stock out / (total items*days in month))

Month%_stockout
Sep-2321%

 

Any help would be much appreciated 🙂

 

Thanks

1 ACCEPTED SOLUTION

Hi @SIA3720 ,

 

According to your statement, I think the sample you shared before is not all data.

Please try code as below to create a measure.

%_stockout =
VAR _GENERATE =
    GENERATE ( 'Calendar', VALUES ( 'Table'[Item] ) )
VAR _Findstockout =
    FILTER (
        _GENERATE,
        CALCULATE ( SUM ( 'Table'[Running_stock_balance] ) = BLANK () )
    )
VAR _TOTAL =
    DAY ( CALCULATE ( MAX ( 'Calendar'[Date] ) ) ) * DISTINCTCOUNT ( 'Table'[Item] )
RETURN
    DIVIDE ( COUNTROWS ( _Findstockout ), _TOTAL )

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

5 REPLIES 5
SIA3720
Frequent Visitor

Hi Ahmed, 

 

To get to 21%, I summed the number of days each item had 0 stock, which totalled 19. I then divided by 90 (30 days * 3 items - the maximum number of days each item could have been in stock. 

 

A table may explain it better:

 

Workings:

DateNum_Stock_outsCount_Max_Stock_ItemsCount_Actual_Stock_Items
01/09/2023033
02/09/2023033
03/09/2023033
04/09/2023033
05/09/2023033
06/09/2023033
07/09/2023132
08/09/2023231
09/09/2023231
10/09/2023231
11/09/2023132
12/09/2023132
13/09/2023132
14/09/2023132
15/09/2023132
16/09/2023132
17/09/2023132
18/09/2023132
19/09/2023132
20/09/2023132
21/09/2023132
22/09/2023132
23/09/2023033
24/09/2023033
25/09/2023033
26/09/2023033
27/09/2023033
28/09/2023033
29/09/2023033
30/09/2023033
Total199071

 

Results:

 Sep-23
Stockout%21%
StockAvailability%79%

 

Thanks 🙂

Hi,

I do not see any connection between the table that you shared in the first post and this one.  Which of these 2 tables is the input table and which are the input columns?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi,

 

The sample data in the first post is the input data showing the running stock balance per item. 

The workings table in my second post shows a count of items with 0 stock for each day, a count of all items per day, and a count of items with available stock per day.   I created this table to demonstrate how I performed to stock out calculation. 

thanks

 

Hi @SIA3720 ,

 

According to your statement, I think the sample you shared before is not all data.

Please try code as below to create a measure.

%_stockout =
VAR _GENERATE =
    GENERATE ( 'Calendar', VALUES ( 'Table'[Item] ) )
VAR _Findstockout =
    FILTER (
        _GENERATE,
        CALCULATE ( SUM ( 'Table'[Running_stock_balance] ) = BLANK () )
    )
VAR _TOTAL =
    DAY ( CALCULATE ( MAX ( 'Calendar'[Date] ) ) ) * DISTINCTCOUNT ( 'Table'[Item] )
RETURN
    DIVIDE ( COUNTROWS ( _Findstockout ), _TOTAL )

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Ahmedx
Super User
Super User

explain how you got 21%
from your data show what was divided by what

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.