finding closest record and averaging over time periods