Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

Calculating availability based on reservations

Hi all,

 

I've encountered an analytical problem I've trouble with executing in PowerBI and could probably use your help.

 

I've got the following single table with reservations (simplified example):

 

ReservationRoomStartEnd
1A01-12-2019 9:0002-12-2019 4:00
2B02-12-2019 7:0002-12-2019 15:00
3A02-12-2019 6:0002-12-2019 23:00
4B03-12-2019 8:0003-12-2019 16:00
5B03-12-2019 17:0004-12-2019 10:00
6A03-12-2019 2:0003-12-2019 6:00
7A03-12-2019 15:0003-12-2019 20:00
............

 

What I'd like to achieve is a matrix with individual dates on the columns and rooms on the rows, showing how many times a room was available after 5:00 for a period of at least 1.5 hours and while being reserved at least once on the same day after 5:00.

 

So for room A:

StartEndStatusDuration (hours)
01-12-2019 9:0002-12-2019 4:00Occupied19
02-12-2019 4:0002-12-2019 6:00Available2
02-12-2019 6:0002-12-2019 23:00Occupied17
02-12-2019 23:0003-12-2019 2:00Available3
03-12-2019 2:0003-12-2019 6:00Occupied4
03-12-2019 6:0003-12-2019 15:00Available9
03-12-2019 15:0003-12-2019 20:00Occupied5

 

So on 01-12-2019, you get 1 reservation that lasts until the next day at 4:00. Conditions have not been met.

.... on 02-12-2019, you get 1 reservation from 6:00-23:00, after which there's availability of 3 hours until the next reservation so all conditions have been met once.

.... on 03-12-2019, you get 2 reservations, first from 2:00-6:00 and then from 15:00-20:00; this means there was a reservation going on at/after 5:00, resulting in all availibilities greater than 1.5 hours to become valid. In between the reservations there is a gap of 9 hours; that's the first 'gap' that meets all conditions. The second gap is after 20:00 with no following reservation known, one can assume that there was basically infinite availability after that, so at least 1.5 hours.

 

With the example above, you would get:

 

 01-12-201902-12-201903-12-201904-12-2019
A0120
B0101

 

Any idea on how to create something like this?

 

Your help is very much appreciated. ๐Ÿ™‚