In the end, I got the right numbers. There are a number of solutions around for populating a column adjacent to the dataset, but I had a lot of trouble getting a single value solution.
The way this works is pretty similar to most SUMPRODUCT formulae:
- first 2 result sets filter in the bookings where part or all the period lies between the search dates
- third result set returns the avg PPN for all filtered bookings
- last result set uses a nested IF() to return the number of booking days that fall between the 2 search dates
Hope it helps someone else :)
=ARRAYFORMULA(SUMPRODUCT(NOT(GT(Bookings_StartDate,ReportExec_EndDate)), NOT(LT(Bookings_EndDate,ReportExec_StartDate)),IF(Bookings_Nights,(Bookings_ValueA/Bookings_Nights),0),(IF(Bookings_EndDate>ReportExec_EndDate,ReportExec_EndDate+1,Bookings_EndDate)-IF(Bookings_StartDate<ReportExec_StartDate,ReportExec_StartDate,Bookings_StartDate))))