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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
GilesWalker
Skilled Sharer
Skilled Sharer

Hotel occupancy rates

Hi everyone,

 

I have been stuck on this issue for a few days ad am probably over thinking things, so I am hoping someone out there can provide a tidy solution.

 

I have created some dummy data for a hotel and need to work out the occupancy rates (total rooms / filled rooms). The total rooms is 48, here is the data:

 

Room_IDGuest_IDDate_fromDate_to
109741/01/20166/01/2016
217851/01/20165/01/2016
210161/01/20166/01/2016
116531/01/20165/01/2016
2091291/01/20163/01/2016
214822/01/20163/01/2016
215962/01/20163/01/2016
204132/01/20167/01/2016
108183/01/20166/01/2016
1151015/01/20168/01/2016
207125/01/20167/01/2016
104236/01/20167/01/2016
4031387/01/201612/01/2016
111157/01/201611/01/2016
4041317/01/201612/01/2016
106957/01/201612/01/2016
304958/01/20169/01/2016
302178/01/201613/01/2016
2121099/01/201612/01/2016
30249/01/201614/01/2016

 

Its a fairly straight forward table. However my issue is if I want to work out the occupancy rate on a day, week, month, or year how to get a dax formula to calculate the days inbetween the date_from and date_to. I have thought it could be done with total number of days in the relevant time frame, however would be interested to see the communities ideas.

 

The report has a date key with a continuous dates and all the relevant weeks, months, etc. This is linked via the Date_from column.

 

Thanks,

 

Giles

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Think I've got it solved for you:

 

Add an index column to your Bookings table, since I'm assuming the GuestID refers to a specific person and that person can book multiple rooms at a time or across a given time period.

 

Add a Date Dimension.

 

Your model should look like the following:

 

Hotel Occupancy.png

 

 

Create the following measures:

Rooms Occupied:=CALCULATE(DISTINCTCOUNT(Bookings[Index Column]),Filter(Bookings,[Date_from]<=LASTDATE(DimDate[Date])&&[Date_to]>=FIRSTDATE(DimDate[Date])))

 

Rooms Available (Total for Selected Dates):=CALCULATE(DISTINCTCOUNT(DimDate[Date]))*48

 

Total Dates Booked:=CALCULATE(DISTINCTCOUNT(DimDate[Date]),Bookings)

 

Total Rooms Occupied:=SUMX(Bookings,[Rooms Occupied]*[Total Dates Booked])

 

OccupancyRate:=DIVIDE([Total Rooms Occupied],[Rooms Available (Total for Selected Dates)])

 

Or

 

OccupancyRate:=DIVIDE([Total Rooms Occupied],[Rooms Available (Total for Selected Dates)])*DIVIDE([Rows in Bookings],[Rows in Bookings])

 

Pivot Table Examples:

Pivot Table Example 1.png

 

Pivot table Example 2.png

 

Please mark it as a solution or give a kudo if it works for you, otherwise let me know if you run into an issue and I'll do my best to assist. Go To bipatterns.com for more techniques and user guides.

 

Thanks,

Ryan Durkin

 

View solution in original post

31 REPLIES 31
edinvz
Frequent Visitor

Not sure if the problem is too complex or I confused you.

 

If anyone is willing to help I will provide more details.

 

Edin

edinvz
Frequent Visitor

Thanks for your replies @GilesWalker and @Ashish_Mathur, they are highly appreciated.

 

I have attemted to use provided formula to create a measure, but it throws the error I have experienced with other attempts to create this measure: 

 

'The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.'

 

I might be applying it in a wrong way, but it also seems like the question of how my data table looks like as pointed by @Ashish_Mathur can be of use.

 

My initial data table contains rows for each reservation per (berth) room, customer, product, start date and end date.

 

IdBerth__cEnd_Day__cStart_Day__cProducts__cAccountID
a4Jb0a4Kb016-06-1615-06-16a7jb0 
a4Jb0a4Kb023-09-1722-09-17a7jb0 
a4Jb0a4Kb023-09-1722-09-17a7jb0 
a4Jb0a4Kb024-09-1723-09-17a7jb0 
a4Jb0a4Kb020-06-1615-06-16a7jb0 
a4Jb0a4Kb015-08-1713-08-17a7jb0 
a4Jb0a4Kb003-08-1702-08-17a7jb0 
a4Jb0a4Kb016-06-1615-06-16a7jb0 

 

Obviously all of the values appear many times, as the dataset contains few years of reservations.

 

Edit: what I am trying to get is the occupancy by month and length for instance, the example of occupancy length for one period is presented below. Columns Count and Area as well as length of berths are added into Data table from related tables. The primary question is how to find the Occ count based on Data table. 

 

LengthCountAreaOcc CountOcc AreaOcc% CountOcc% Area
6            8        144         6.40   115.2080%80%
7          10        210         8.00   168.0080%80%
12          30     1,440        24.00 1,152.0080%80%
13.5          20     1,080        16.00   864.0080%80%
15          30     2,250        24.00 1,800.0080%80%
17          20     1,700        16.00 1,360.0080%80%
18          10     1,080         8.00   864.0080%80%

 

 

 

Thanks in advance and let me know if I can help you with any additional information

 

Edin 

 

 

Hi,

 

I do not understand how you have computed the numbers in the Occ Count column.  Please explain in detail.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

My apologies for not being clear enough. 

 

That information comes from a different table. But as I said the focus is on Occupied Berths Count and that's the only bit of information to be calculated based on the presented data table.

 

I hope it makes more sense now.


Thansk a lot!

 

Edin

I still do not understand.  How have you computed the numbers in the Occ Count column?  How did you arrive at the numbers - 6.4,8,24 etc? 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

That's exactly what I want to get:, the second table is the output I am afterL my question is how to create measure that would calculate Occupancy Count based on the first table (Data table that contains reservations and all related features).

 

 

edinvz
Frequent Visitor

Dear Power BI pros 🙂

 

I have tried to crack this one for some time and still cannot manage to get what I need.

 

I want to get the measure that would calculate the number of occupied rooms each day, but also getting the average number of rooms occupied when aggregated to monthly and annual basis.

 

I have solved it by creating the Calculated Column using the measure [Rooms Occupied] provided by rdurkin and then averaged it. It works just fine for total occupancy, but wait does not allow for slicing and dicing by different segments e.g. product, room type, size and similar. 

 

I would appreciate if anyone could give a try to suggest a solution for the problem outlined above.

 

And just in case it makes difference, I am working in Excel Power Pivot, rather than Power BI.

 

Thanks in advance and looking forward to see how genius Dax measures can be.

 

Edin

 

Hi @edinvz,

 

Share the link from where i can download your Excel workbook and also the expected result there.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@edinvz - I managed to find a solution to this and have used it a few times and it does work well:

 

Daily Table =
FILTER (
CROSSJOIN ( Table1, CALENDARAUTO () ),
Table1[date_from] <= [Date]
&& [Date]
<=
VAR EndDate = Table1[date_to]
RETURN
IF ( EndDate = BLANK (), TODAY (), EndDate )
)

Anonymous
Not applicable

Think I've got it solved for you:

 

Add an index column to your Bookings table, since I'm assuming the GuestID refers to a specific person and that person can book multiple rooms at a time or across a given time period.

 

Add a Date Dimension.

 

Your model should look like the following:

 

Hotel Occupancy.png

 

 

Create the following measures:

Rooms Occupied:=CALCULATE(DISTINCTCOUNT(Bookings[Index Column]),Filter(Bookings,[Date_from]<=LASTDATE(DimDate[Date])&&[Date_to]>=FIRSTDATE(DimDate[Date])))

 

Rooms Available (Total for Selected Dates):=CALCULATE(DISTINCTCOUNT(DimDate[Date]))*48

 

Total Dates Booked:=CALCULATE(DISTINCTCOUNT(DimDate[Date]),Bookings)

 

Total Rooms Occupied:=SUMX(Bookings,[Rooms Occupied]*[Total Dates Booked])

 

OccupancyRate:=DIVIDE([Total Rooms Occupied],[Rooms Available (Total for Selected Dates)])

 

Or

 

OccupancyRate:=DIVIDE([Total Rooms Occupied],[Rooms Available (Total for Selected Dates)])*DIVIDE([Rows in Bookings],[Rows in Bookings])

 

Pivot Table Examples:

Pivot Table Example 1.png

 

Pivot table Example 2.png

 

Please mark it as a solution or give a kudo if it works for you, otherwise let me know if you run into an issue and I'll do my best to assist. Go To bipatterns.com for more techniques and user guides.

 

Thanks,

Ryan Durkin

 

Any idea how to fill in the blanks ?
E.g. there should be 5 on 7th and 9 through out September...
OR.PNG

Hi,

 

Explain the question and share the data (in a format that can be pasted in an Excel file)


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

I'm using @Anonymous proposed solution and I get blanks where there is no-one checking in.

Everything else is correct, I just need the numbers to be cumulative

@Anonymous - thanks for you help with this your solution worked as it takes into account the total available days for rooms and then uses the actual count of time a room is booked.

 

@sdjensen - thanks for your assistance with this, you were spot on in that you have to take into account the days available compared to days booked out per room.

 

@KHorseman - thanks for all the help with this and for clarifying what the measures were doing. 

@KHorseman - Having some trouble this query again, turned out the numbers were not calculating correctly and part of the formula you gave worked with a bit of tweaking to give me the total days booked. To calculate the total days booked I am using this:

 

Inclusive days booked = SUMX(

FILTER(Bookings, Bookings[Date_from] <= LASTDATE (DateKey[Date]) && Bookings[Date_to] >= FIRSTDATE (DateKey[Date])),

COUNTROWS(DATESBETWEEN (DateKey[Date],Bookings[Date_from],Bookings[Date_to])))

 

The issue I run into is with the reporting over time periods. If I have a room booked out from 30 January to 4 February that means that in January there were two days booked, and in February there were four days booked. However the above formula says booked for six days which is correct however it allocates those six days to the month i have the datekey relationship linked to (i.e if the date_from is in January then January gets the six days). I have tried changing the DateKey table relationship to be linked to either Date_from and Date_to in the bookings table, it makes no difference.

 

Is there a filter that can be used so that when filtering by a month/week/quarter etc. a measure will calculate only the days in the month. In this example January would have two days allocated (30 and 31 January), and February would get four days (1-4 February).

 

Heres a picture of what I am currently dealing with:

 

Occupancy.PNG

 

Thanks,

 

Giles

@GilesWalker For any of the solutions I've suggested there should be no relationship at all between Bookings and DateKey. Any relationship will break these durational measure patterns. From there you should be able to use this:

 

Inclusive Days Booked = SUMX(
	FILTER(
		Bookings,
		Bookings[Date_from] <= LASTDATE(DateKey[Date]) &&
		Bookings[Date_to] >= FIRSTDATE(DateKey[Date])
	),
	CALCULATE(
		DISTINCTCOUNT(DateKey[Date]),
		DATESBETWEEN(
			DateKey[Date],
			Bookings[Date_from],
			Bookings[Date_to]
		)
	)
)

This only works sensibly if you only have one room selected at a time, or if you do something like a clustered bar chart with room_ID as the legend. Otherwise the same day will be counted multiple times, once for each room that is occupied during the time period. But your screenshot looks like it's only for one room at a time anyway.

 

I'm fairly certain that putting a CALCULATE inside a SUMX is some sort of DAX sin but I can live with that.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

@GilesWalker

This is a pretty interesting request.  If you have a dummy excel file available, I'd be happy to provide a solution.  Attach it here if possible.  In order to help I'll need a better understanding of the data model in this case.

 

 

@Anonymous happy to, how do I do that?

@GilesWalker So that you don't have to wade through that other thread to pick the best of the offered solutions, I'd recommend the following:

 

First, that relationship between Date_from and the date table. There should be no table relationships for this to work. Again, see that other thread for the details. Then here's your occupancy measure:

 

Occupancy = CALCULATE(
DISTINCTCOUNT(TableName[Room_ID]),
FILTER(
TableName,
TableName[Date_from] <= LASTDATE(DateTable[Date]) &&
TableName[Date_to] >= FIRSTDATE(DateTable[Date])
)
)

 

You can place any time period from the date table next to this measure and it will work. A month, a week, a single day... I have it counting each room only once, but you may want to do a distinctcount of guests instead if you want to count the same room multiple times if it is occupied multiple times in a period. Or you could do a regular count of rooms instead of a distinctcount. Depends on your specific needs.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks @KHorseman I just finished reading through the information on you link and your idea seems nice and clean. Once I get into work in a couple hours I will try both yours and @Sean idea to see what works best.

 

I will reply back with what I have done.

 

Giles

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.