Forum Discussion
Help: Occupancy rate
- 7 years ago
Hi Anonymous
I've had a look at this and have attached a PBIX with some suggestions.
The basic measure you're wanting is an "events in progress" type measure.
Generally speaking, you can either
- Have a table with one row per session, with columns for start and end datetime values
- Transform your table so that there is one row for every datetime value for which a session is ongoing (at some time granularity, e.g. hourly
In my sample file I have used both methods. Here is what I did:
- For Option #1, Created a ChargingData table with dummy data looking like this (I created a random dataset with a DAX calculated table):
- Created a Date table covering the range of dates in ChargingData
- Created a Time table with hourly granularity. Each row really corresponds to an hourly interval:
- Created an Occupancy measure
Occupancy = VAR MinDateTime = MIN ( 'Date'[Date] ) + MIN ( 'Time'[Time] ) VAR MaxDateTime = MAX ( 'Date'[Date] ) + MAX ( 'Time'[Time End] ) RETURN CALCULATE ( DISTINCTCOUNT ( ChargingData[Session ID] ), // Could also use COUNTROWS ( ChargingData ) ChargingData[Start date] < MaxDateTime, ChargingData[End date] >= MinDateTime )Note that there is no relationship between Occupancy and either Date or Time.
This measure counts the number of distinct sessions that occur during the selected date/time interval. - For Option #2, created a ChargingDataReshaped table. This table contains one row for each Session ID & hourly interval during which that Session ID is active. The DAX code for this table is in the PBIX.
Note that this table is related to Date & Time - Created a measure Occupancy v2 which is simply:
Occupancy v2 = DISTINCTCOUNT ( CharginDataReshaped[Session ID] )
- Now both Occupany & Occupancy v2 give the same results when filtered by Date & Time. I also created a Charge ID table that filters both ChargingData & ChargingDataReshaped.
- Now the Occupancy measures can be visualized however you want, e.g.
I would expect Option #2 to perform better in general. However, you may want to keep both versions of the data in the model for different purposes.
Hopefully that's of some use and can be adapted as needed.
Regards,
Owen
how do you want to count the occupancy exactly? the way I understand it, it will change depending to what time frame you compare it, is that correct? E.g. looking at your example:
| Sessions ID | Start date | End date | Duration | Volume | Charge ID |
| 1 | 01/01/2019 13:15 | 01/01/2019 17:22 | 04:07:30 | 3 | 101 |
if I calculate the occupancy for 01/01/2019 it will be ~4h/24h, but if I calculate it for 01/01/2019-02/01/2019 it will be ~4h/48h, correct? if that's the case then you definitely need to use a measure, not a column
what's the time span that you look at? days, weeks, years? can you also provide some more rows with more tricky examples e.g. multiple start/end dates - can they overlap or not? if they can overlap does it count as 100% occupancy at this point in time or 200%? in the copiable format, as I posted above
- Anonymous7 years agoNot applicable
Hello Stachu,
I'm sorry for not specifying that beforehand. The occupancy rate I want in the end is per hour, like OwenAuger did in his solution.
Because like you said, sessions can overlap with each other, and when they do, the occupancy of the station is 100%, since it has 2 sockets only.
Thank you for thinking and helping with a solution!