Click to See Complete Forum and Search --> : Counting range with gaps in records


johnstk
November 22nd, 2007, 03:56 AM
Trying to calculate Days In Stock value:
I have an opening quantity value (@fOpQtyBal) at the beginning of a period (displayed in Group header). Detail section lists all quantity movements for the period by date. I need to calculate the number of days that there is positive stock (Balance > 0).
Data looks like this:
Qty Balance
fOpQtyBal 10 10
01/01/2007 -1 9
03/01/2007 -9 0
10/01/2007 6 6

Days in stock is 31 days in January less 7 days (03/01 - 10/01) where there was no stock = 24.

Have tried a few ideas but get stuck on looping through the days because there are some days where there are no records. Any heads up?

Shaikh.Riyaz.a
November 23rd, 2007, 07:58 AM
Use the running total and set the formula for it as Balance>0 to execute.

Lugh
November 26th, 2007, 11:26 AM
You should also look into the Next and Previous functions in your formula. These will read the values from the records immediately after and before the current record. Doing a DateDiff between the Previous record and the current record should get you the number of days during which the Balance > 0.