Count Activities in a Date Range

Today’s challenge is to count how many guests stayed at a hotel, in a specific date range, based on the guest arrival and departure dates.

guestsdaterange01

Find Specific Dates

In previous examples, we’ve seen how to check if a specific date falls within a date range. For example, if you have a list of orders, you can use SUMIF or SUMIFS, to add up all the orders between a start and end date. You can see the written instructions for this on my website.

sumdaterange02

Guest Visits

It is a little trickier to count hotel guests though, because the booking table only shows the guest arrival and departure dates. We have to use those dates, to see if any part of a guest’s visit overlapped our date range.

For this report, we want the number of guest who were in the hotel during the reporting period of December 7th to 9th. I’ve highlighted the records that should be included, when we create a formula to count the guests.

guestsdaterange02

When Did the Guest Leave?

To calculate if the guest’s visit was within the date range, we’ll start with two short formulas.

The first formula will check the guest’s departure date – was it on or after the start of our date range? (If they left before the date range started, they won’t be counted)

The report start date is in cell C3, and guest’s departure date is in cell C6, so the formula is:

=C6>=$C$3

The first 5 guests all left before December 7th, so the result in those rows is FALSE.

guestsdaterange03

When Did the Guest Arrive?

The second formula will check the guest’s arrival date – was it on or before the end of our date range? (If they arrived after the date range ended, they won’t be counted)

The report start date is in cell D3, and guest’s arrival date is in cell B6, so the formula is:

=B6<=$D$3

Guest #11 arrived on December 10, and that is after the report end date of December 9th, so the result in that row is FALSE.

guestsdaterange04

Both Results TRUE

If the result of both formulas is TRUE, then the guest stayed at the hotel during the reporting period:

  • they arrived on or before December 9th
  • they departed on or after December 7th

We’ll use a SUMIFS formula to check those two columns, and sum then number of guests in column E. I’ve changed the column headings in F and G, to Dep Check and Arr Check.

Enter this formula in cell F3:

=SUMIFS(tblGuests[Guests], tblGuests[Dep Check],TRUE, tblGuests[Arr Check],TRUE)

guestsdaterange05

Get the Result

The result is 11, and that matches the total when the numbers are selected in the manually highlighted rows. You can see that automatic calculation in the Status Bar.

guestsdaterange06

Download the Sample File

To see how the formulas work, you can download the sample file from my Contextures website. On the Excel Sample Files page, go to the Functions section, and look for FN0036 – Count Hotel Guests in Date Range.

The zipped file is in xlsx format, and does not contain macros. It also has another, more complex, example of counting in a date range. Guests are counted by their hotel loyalty program level, and the number of nights booked in the date range is also calculated.

Video: Count Numbers in a Range – COUNTIFS

Using a simpler example, this video shows how to use the COUNTIFS function to count cells based on a range of numbers.

The minimum and maximum numbers are entered on the worksheet, so it’s easy to change the number range, when needed.

More COUNTIFS Examples

Excel Count and Sum in Date Range

Excel Count If Greater Than or Less Than

guestsdaterange07

____________________________

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.