Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
ihatethis
New Member

Calculating Daily occupancy from rows with start and end dates

I have two tables: the example below and a generic date table. 

 

Guest IDBed IDCheck-In DateCheckout Date
110001/01/202601/08/2026
210201/01/202601/05/2026
310412/31/202501/10/2026
410601/02/202601/03/2026

 

 

If I wanted to create a table to show the occupancy per night, how could I go about that with just the date range of check in and check out? Some stays are months long, so any method that pulls all the middle dates out into a column or row wouldn't necessarily be ideal

 

Output wanted:

DateGuests
12-311
01-013
01-024
01-033
2 ACCEPTED SOLUTIONS
Zanqueta
Super User
Super User

Hello @ihatethis 

 

Best Practice Approach

Use a measure that checks if a given date falls within the check-in and checkout range for each guest, and then aggregates across all guests.

Step 1: Ensure Relationships

  • Your Date table should be marked as a Date Table in Power BI.
  • There is no direct relationship between the Date table and the Guest table because the occupancy spans ranges. We will handle this with DAX.

Step 2: Create the Measure

Daily Occupancy =
VAR SelectedDate = MAX('Date'[Date])
RETURN
CALCULATE(
    COUNTROWS('GuestTable'),
    FILTER(
        'GuestTable',
        'GuestTable'[Check-In Date] <= SelectedDate &&
        'GuestTable'[Checkout Date] > SelectedDate
    )
)

 

Official Reference:
 

If this response was helpful in any way, I’d gladly accept a 👍much like the joy of seeing a DAX measure work first time without needing another FILTER.

Please mark it as the correct solution. It helps other community members find their way faster (and saves them from another endless loop 🌀.

 

If this response was helpful in any way, I’d gladly accept a kudo.
Please mark it as the correct solution. It helps other community members find their way faster.
Connect with me on LinkedIn

View solution in original post

Jaywant-Thorat
Super User
Super User

This is a classic occupancy / hotel nights problem and it’s 100% solvable with DAX, without exploding dates into rows.

Correct Modeling (Important)

You already have:

  • Fact table: Stays (Guest ID, Check-In Date, Checkout Date)

  • Date table: Calendar[Date]

Create ONE relationship only:

  • Calendar[Date] → Stays[Check-In Date] (active)

(Checkout date will be handled in DAX, not relationships)

DAX Measure: Occupancy per Night

Create this measure:

Guests Occupied =
VAR CurrentDate =
SELECTEDVALUE ( 'Calendar'[Date] )
RETURN
CALCULATE (
DISTINCTCOUNT ( Stays[Guest ID] ),
FILTER (
ALL ( Stays ),
Stays[Check-In Date] <= CurrentDate
&& Stays[Checkout Date] > CurrentDate
)
)

Logic (simple)

  • Guest is counted if:

    • Checked in on or before the night

    • Checked out after the night

  • Checkout day is not counted (standard hotel logic)

Build the Visual

Create a Table visual:

  • Rows → Calendar[Date]

  • Values → Guests Occupied

(Optional: filter dates where Guests > 0)

 

=================================================================
Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Jaywant Thorat | MCT | Data Analytics Coach
LinkedIn: https://www.linkedin.com/in/jaywantthorat/
Join #MissionPowerBIBharat = https://shorturl.at/5ViW9
#MissionPowerBIBharat
LIVE with Jaywant Thorat from 10 Jan 2026
8 Days | 8 Sessions | 1 hr daily | 100% Free

View solution in original post

4 REPLIES 4
Jaywant-Thorat
Super User
Super User

This is a classic occupancy / hotel nights problem and it’s 100% solvable with DAX, without exploding dates into rows.

Correct Modeling (Important)

You already have:

  • Fact table: Stays (Guest ID, Check-In Date, Checkout Date)

  • Date table: Calendar[Date]

Create ONE relationship only:

  • Calendar[Date] → Stays[Check-In Date] (active)

(Checkout date will be handled in DAX, not relationships)

DAX Measure: Occupancy per Night

Create this measure:

Guests Occupied =
VAR CurrentDate =
SELECTEDVALUE ( 'Calendar'[Date] )
RETURN
CALCULATE (
DISTINCTCOUNT ( Stays[Guest ID] ),
FILTER (
ALL ( Stays ),
Stays[Check-In Date] <= CurrentDate
&& Stays[Checkout Date] > CurrentDate
)
)

Logic (simple)

  • Guest is counted if:

    • Checked in on or before the night

    • Checked out after the night

  • Checkout day is not counted (standard hotel logic)

Build the Visual

Create a Table visual:

  • Rows → Calendar[Date]

  • Values → Guests Occupied

(Optional: filter dates where Guests > 0)

 

=================================================================
Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Jaywant Thorat | MCT | Data Analytics Coach
LinkedIn: https://www.linkedin.com/in/jaywantthorat/
Join #MissionPowerBIBharat = https://shorturl.at/5ViW9
#MissionPowerBIBharat
LIVE with Jaywant Thorat from 10 Jan 2026
8 Days | 8 Sessions | 1 hr daily | 100% Free

cengizhanarslan
Super User
Super User

Please try the formula below:

Guests (Occupied Nights) =
VAR d = MAX ( DimDate[Date] )
RETURN
CALCULATE (
    DISTINCTCOUNT ( Stays[Guest ID] ),
    FILTER (
        ALL ( Stays ),
        Stays[Check-In Date] <= d
            && Stays[Checkout Date] > d
    )
)
___________________________________________________________________________________________________________________________________
If this helped, ✓ Mark as Solution | Kudos appreciated
Connect on LinkedIn | Follow on Medium
AI-assisted tools are used solely for wording support. All conclusions are independently reviewed.
Zanqueta
Super User
Super User

Hello @ihatethis 

 

Best Practice Approach

Use a measure that checks if a given date falls within the check-in and checkout range for each guest, and then aggregates across all guests.

Step 1: Ensure Relationships

  • Your Date table should be marked as a Date Table in Power BI.
  • There is no direct relationship between the Date table and the Guest table because the occupancy spans ranges. We will handle this with DAX.

Step 2: Create the Measure

Daily Occupancy =
VAR SelectedDate = MAX('Date'[Date])
RETURN
CALCULATE(
    COUNTROWS('GuestTable'),
    FILTER(
        'GuestTable',
        'GuestTable'[Check-In Date] <= SelectedDate &&
        'GuestTable'[Checkout Date] > SelectedDate
    )
)

 

Official Reference:
 

If this response was helpful in any way, I’d gladly accept a 👍much like the joy of seeing a DAX measure work first time without needing another FILTER.

Please mark it as the correct solution. It helps other community members find their way faster (and saves them from another endless loop 🌀.

 

If this response was helpful in any way, I’d gladly accept a kudo.
Please mark it as the correct solution. It helps other community members find their way faster.
Connect with me on LinkedIn

FBergamaschi
Super User
Super User

Hi @ihatethis 

 

if this is what you are looking for based on the data you gave (hope I interpreted dates in the right way)

 

FBergamaschi_0-1768313502580.png

 

you can find my file here

 

https://drive.google.com/drive/folders/16Qg6qfKEShGp7AEsdnM8CecoV3xD6CiP?usp=drive_link

 

If this helped, please consider giving kudos and mark as a solution

@me in replies or I'll lose your thread

Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page

Consider voting this Power BI idea

Francesco Bergamaschi

MBA, M.Eng, M.Econ, Professor of BI

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.