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
marzwrob
Helper II
Helper II

Calculating out of stock - for products over a period of time, with varied frequency upates

I have a data set which can be seen in a matrix format like this: (showing in matric because it is easier to visualise that updates on stock are not regular):

 

Each product is receiving updates and varied frequency levels.

 

What I want is to calculate how many days in a period of time (e.g., a month) each product was out of stock.

The logic would go something like:

if a stock level changed on Day X to 0, or a negative number, then use this day as a first day of out of stock. If there is another record inserted for this product, and is still 0 or another negative, still use as out of stock. If this new entry is positive, count it as in stock.

Then calculate over a month how many days each product was out of stock. 

Someone help, please? 

 

Sample data: 

Screenshot 2024-02-01 at 16.41.29.png

1 ACCEPTED SOLUTION
v-tianyich-msft
Community Support
Community Support

Hi @marzwrob ,

 

I made simple samples and you can check the results below:

vtianyichmsft_0-1706842151753.png

Measure = var _t = ADDCOLUMNS('Table',"Count",COUNTAX(FILTER(ALL('Table'),[ID]=EARLIER([ID])&&[Value]<=0),[Date]))
RETURN MAXX(_t,[Count])

 

An attachment for your reference. Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

Share some data to work with and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-tianyich-msft
Community Support
Community Support

Hi @marzwrob ,

 

I made simple samples and you can check the results below:

vtianyichmsft_0-1706842151753.png

Measure = var _t = ADDCOLUMNS('Table',"Count",COUNTAX(FILTER(ALL('Table'),[ID]=EARLIER([ID])&&[Value]<=0),[Date]))
RETURN MAXX(_t,[Count])

 

An attachment for your reference. Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.