I am working on a Report and require some help with the query design. In the query, I have the Forecasted Sales and the Forecasted Inventory ( in monthly buckets). What I need to do is to calculate the inventory coverage (in number of months) in each month. The definition of inventory coverage would be as follows:

If the inventory I have at the end of the month is able to meet the demand ( forecasted sales) for the next X months, then the Inventory Coverage that month is X.

Suppose I have the following scenario:

```
Month1 Month2 Month3 Month4 Month5
Net Sales 100 300 300 400 200
Inventory 400 800 500 600 300
Coverage 1.33 2.5 1.5 1 -
```

Calculation: For month 1 : Inventory = 400.

Net sales for month 2 = 300

Hence Inventory that would be left = 400 - 300 = 100

Net Sales for month 3 = 300

The remaining inventory can meet 100/300 = 0.33 of this month.

Hence the Inventory Coverage in month 1 is 1.33

Similarly for month 2 and 3.

Month 4 can cover for the the whole of month 5, and since no further months are available, we would show the coverage as 1.

Can someone help me with this. If someone has done something similar to this, kindly respond.

My table like that:

```
Period Inventory NetSales
201701 400 100
201702 800 300
201703 500 300
201704 600 400
201705 300 200
```

Thanks