Average Interval between Buying Jetta and Magotan

Based on the automobile sales data, calculate the average interval in days between buying the Jetta first and then the Magotan car.

Please note that a customer may buy the car of the same model for several times, and thus there may be several intervals. In this case, we will take the shortest interval, that is, the number of days from the date buying Jetta for the last time to the date buying Magotan for the first time.

Solution:

A
1
=file@s("Volkswagen.txt").import@t()
2
=A1.sort(Customer,Date)
3
=A2.select(Model=="Jetta"||Model=="MAGOTAN").dup@t()
4
=A3.derive(interval(Date[-1],Date):Interval)
5
=A4.select(Model[-1]=="Jetta" && Model=="MAGOTAN" && Customer==Customer[-1])
6
=round(A5.avg(Interval))

The computation in A6 is shown below: