Wait WINDOW "Non-ETM Data: Apportioning Passenger Numbers within the Time Periods ..." NOWAIT NOCLEAR Scan for not DELETED() llDatesInRange = .F. lnNumDaysInRec = END_DATE - START_DATE + 1 DO CASE Case START_DATE <= ldStartPrev and END_DATE > ldStartPrev && Start date before previous date range llDatesInRange = .T. llCurrPeriod = .F. If END_DATE > ldEndPrev && ends later than Prev period end, so all outside lnPrevPass = lnNumDaysPrev / lnNumDaysInRec * PASSENGERS && so only ALL days curr period Else && ends within Prev period lnDaysInPeriod = END_DATE - ldStartPrev + 1 && so only from start of Prev period to rec end date lnPrevPass = lnDaysInPeriod / lnNumDaysInRec * PASSENGERS EndIf Case BETWEEN( START_DATE, ldStartPrev, ldEndPrev) && Start date inside Previous date range llDatesInRange = .T. llCurrPeriod = .F. If END_DATE > ldEndPrev && ends later than Prev period end lnDaysInPeriod = ldEndPrev - START_DATE + 1 && so only from start date to end of Prev period lnPrevPass = lnDaysInPeriod / lnNumDaysInRec * PASSENGERS Else && ends within Prev period, so wholly in Prev period lnPrevPass = PASSENGERS EndIf Case START_DATE <= ldStartCurr and END_DATE > ldStartCurr && Start date before current date range llCurrPeriod = .T. If END_DATE > ldEndCurr && ends later than curr period end, so all straddles lnCurrPass = lnNumDaysCurr / lnNumDaysInRec * PASSENGERS && so only ALL days within curr period Else && ends within curr period lnDaysInPeriod = END_DATE - ldStartCurr + 1 && so only from start of curr period to rec end date lnCurrPass = lnDaysInPeriod / lnNumDaysInRec * PASSENGERS EndIf Case BETWEEN( START_DATE, ldStartCurr, ldEndCurr) && Start date inside current date range llDatesInRange = .T. llCurrPeriod = .T. If END_DATE > ldEndCurr && ends later than curr period end lnDaysInPeriod = ldEndCurr - START_DATE + 1 && so only from start date to end of curr period lnCurrPass = lnDaysInPeriod / lnNumDaysInRec * PASSENGERS Else && ends within curr period, so wholly in curr period lnCurrPass = PASSENGERS && ... so count whole of rec period EndIf EndCASE If llDatesInRange If llCurrPeriod Replace CURRPASS with lnCurrPass Else Replace PREVPASS with lnPrevPass EndIf EndIf EndSCAN