I am developing a calendar tool for hotel bookings where I need to compute the average nightly rate for reservations that occur between two specified search dates. Here are some important factors to consider:
- Bookings are entered with a check-in date and a check-out date.
- Each booking has a single price listed in the same row.
- The check-out date is counted as available since the room will be empty by the daily check-in time.
- I need to focus only on the booking values for the days that fall within the two search dates.
- It’s important to note that bookings may go beyond the first and second search dates, but I will disregard their values for dates outside the specified range.
- I prefer to achieve this using formulas instead of coding.
I’ve been experimenting with a SUMPRODUCT formula for most of the day, and I’m close to achieving my goal; however, my current approach only provides the total count of occupied rooms during the specified period. Here’s the formula I have:
=ARRAYFORMULA(SUMPRODUCT(GTE(EndDate_Bookings, StartDate_Report+1), LTE(StartDate_Bookings, EndDate_Report+0),IF((StartDate_Bookings<=StartDate_Report)*(EndDate_Bookings>=EndDate_Report),((EndDate_Report-StartDate_Report+1)),IF(StartDate_Bookings<StartDate_Report,EndDate_Bookings-StartDate_Report,IF(EndDate_Bookings>EndDate_Report,(EndDate_Report+1)-StartDate_Bookings,0)))
I suspect the issue lies in the array formula only producing a result for the first IF() condition, which seems incorrect. For clarity, here is an overview of the named ranges:
- StartDate_Report / EndDate_Report = the two search dates.
- StartDate_Bookings / EndDate_Bookings = columns for check-in and check-out dates.
The first IF() identifies all bookings overlapping with the search dates, the second checks for bookings that finish before the first search date, and the third looks for bookings that start after the second search date. Working with Google Sheets feels complex compared to Excel for me, so any advice would be greatly appreciated!