Skip to content
Advertisement

Starting and Ending a row-count based on values in another column

There is a need to monitor the performance of a warehouse of goods. Please refer to the table containing data for one warehouse below:

enter image description here

WK_NO: Week number; Problem: Problem faced on that particular week. Empty cells are NULLs.

I need to create the 3rd column:

Weeks on list: A column indicating the number of weeks that a particular warehouse is being monitored as of that particular week.

Required Logic:

Initially the column’s values are to be 0. If a warehouse is encountering problems continuously for 4 weeks, it is put onto a “list” and a counter starts, indicating the number of weeks the warehouse has been problematic. And if the warehouse is problem-free for 4 continuous weeks after facing problems, the counter resets to 0 and stays 0 until there is another 4 weeks of problems.

Code to generate data shown above:

Any help is much appreciated.

Update:

Some solutions are failing when bringing in data for multiple warehouses.

Updated the code generation script with W_NO which is the warehouse ID, for your consideration.

Advertisement

Answer

Consider below query for updated question:

enter image description here

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement