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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Matrix as Gantt Chart for Room Utilisation - multiple start and end times

Hi All

 

I've been searching the community and indeed the internet for a few weeks now and I still can't find what I'm looking for.

 

I have a requirement to show utilisation of an operating theatre per date.

I created a time gantt chart using the matrix visualisation incrementing by 15 minute slots and showed the utilisation of a room based on the earliest 'into theatre' time of procedures performed on a specific date and the latest 'out of theatre' time of the procedures performed.

I managed to achieve this easily enough with the below code and conditional formatting.

 

 

 

Step 1 = 
var CathlabStartTime = 
CALCULATE(
    MIN('cathlab theatre events'[Rounded Earliest Time]),
    REMOVEFILTERS(dim_time[time])
)
var CathlabEndTime =
CALCULATE(
    MAX('cathlab theatre events'[Rounded Latest Time]),
    REMOVEFILTERS(dim_time[time])
)
var CathlabUtilisation =
    MIN(dim_time[Rounded Time]) >= CathlabStartTime
    && MAX(dim_time[Rounded Time]) <= CathlabEndTime
var Result = 
IF(
    CathlabUtilisation,
    1,0
)
RETURN
    Result

 

 

 

 

CiaraD_0-1661877752711.png

 

Now I'd like to show the utilisation of the theatre but use each individual cases start and finish time and see each row have multiple sections coloured where the room was in use based on these start and finish times.  Below is a sample dataset and how I'd like the visual to look.

Theatre Event KeySurgery DateOperating TheatreStartFinishDuration
114/07/2022OR107:30:0008:30:001:00:00
214/07/2022OR109:15:0012:15:003:00:00
314/07/2022OR113:30:0014:30:001:00:00
414/07/2022OR114:30:0014:45:000:15:00
514/07/2022OR115:00:0015:30:000:30:00
614/07/2022OR115:45:0016:15:000:30:00
714/07/2022OR116:45:0017:30:000:45:00
814/07/2022OR207:30:0010:15:002:45:00
914/07/2022OR210:30:0011:30:001:00:00
1014/07/2022OR212:45:0013:30:000:45:00
1114/07/2022OR213:30:0014:30:001:00:00
1214/07/2022OR215:15:0016:15:001:00:00
1314/07/2022OR217:30:0018:00:000:30:00

 

CiaraD_1-1661878332850.png

 

 

I don't have a relationship between my time dimension and my theatre events fact table but when I do create that relationship and change nothing else my visual actually changes to show the start of each case so I'm sure it's possible ... I just don't know how to bring it about  😄

 

CiaraD_3-1661878641244.png

 

With the relationship between dim_time and 'cathlab theatre events' tables

CiaraD_4-1661879059783.png

 

I appreciate any and all help that anyone can lend.  I will attempt anything and have even started teaching myself R but that will take some time.

 

Thanks

Ciara

1 ACCEPTED SOLUTION
AntonioM
Solution Sage
Solution Sage

Hi @Anonymous ,

 

You should be able to do this with a change or two to the measure you have currently. I've created a rough setup but the idea should work the same. 

 

Keep your time table unlinked, and create a measure like this one

Measure = 
Var _time = SELECTEDVALUE('Time Table'[Time])
Var _activity = CALCULATE(COUNTROWS('Table'), 'Table'[Start]<= _time , 'Table'[Finish] > _time)
Return
_activity + 0

The idea is to look at the current time, then count how many events are active at that time, using CALCULATE to filter the table.

 

If you add the 'Operating Theatre' field into you rows, turn off 'stepped layout' under row headers formatting and then add this measure to values

 

AntonioM_0-1661942348808.png

AntonioM_2-1661942463826.png

 

That will give you something like this

AntonioM_1-1661942392132.png

And then you can format the 1s to show colour and the 0s to be blank, as you have before.

 

 

Hope that helps, 

Any problems please let me know. 

 

View solution in original post

6 REPLIES 6
elendil5259
Frequent Visitor

Hi there, 

I have a similar problem and would like to understand your initial solution in detail. 

 

Could you explain a little more about the individual measures/columns/data fields you created?

 

In particular:

  • dim_time[time]
  • cathlab theatre events'[Rounded Earliest Time] 

Thank you!

 

Anonymous
Not applicable

Hi @TomMartens  and @AntonioM 

 

Thank you both so much for your responses.  Antonio I used your code and it worked beautifully (it's so easy when you know how hey? 😄) Thank you so much.

 

Tom, I've to do a little more figuring out with your code in order to implement it but the article you sent is very informative and the pbix will be a great help.  I will be trying this out also.

 

Thanks to you both again.

 

Ciara

TomMartens
Super User
Super User

Hey @Anonymous ,

 

here is a different approach to the one provided by @AntonioM .
As you are facing the event-in-progress challenge (read here: Events-In-Progress – Gerhard Brueckl on BI & Data (gbrueckl.at))

For quite some time now, I do not use DAX to tackle this kind of challenge, instead I create an "expanded" fact table that contains a row for each point described by the start and finish column. the following screenshot shows an excerpt of the expanded table based on the sample data you provided:
image.png
Please be aware that the I changed the datatype of the column Duration to duration (only Power Query does know this data type the dataset does not know this data type.

Then I use Power Query to

  1. determine the number of quarters
  2. create a list
  3. expand this list to rows
  4. create a new column called "Occupied Quarter". I created this column using an line-function, this may seem weird but is very efficient (you will what I'm talking about if you open the Advanced editor in Power Query)
  5. finally I creaed another column with a simple value, this value marks the room as occupied

You can relate your time table to the new column "OccupiedQuarter".

 

This is possible without any DAX, except for the conditional formatting:
image.png
 Depending on the nature of the existing fact table, and the numeric values, I expand the existing table or create an additional table.

From my experience this approach is more efficient than the DAX approach, of course, it consumes additional RAM.

Here you will find a little pbix file: https://tommartens-my.sharepoint.com/:u:/g/personal/tom_minceddata_com/EVpQowE8z3tHlTp6ksx6MDcBKFeMz3qdcInIibt4eRPXjA?e=Jh8jrT

 

Regards,
Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hi @TomMartens ,

 

I am trying to replicate your solution for my own dataset, with the key difference that the "Duration" field you have is a calculated field for me in Power Query, which is essentially the difference between the "Start" & "Finish" Time. 

 

When I was creating a new Column for the "NoOfQuarters", I experienced the following error code:

 

Expression.Error: The number is out of range of a 32 bit integer value.
Details:
2.983333333

 

Would you kindly advise on this please? Many thanks!

Hey @elendil5259 ,

 

please provide a pbix that helps to reproduce the isue you are facing. Make sure that the pbix contains sample data but still relects your semantic model (tables, relationships, calculated columns, and measures). Upload the pbix to OneDrive, Google Drive, or dropbox and share the link. If you are using Excel to create the sample data instead of the manual input method share the spreadsheet as well.

 

Thanks,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
AntonioM
Solution Sage
Solution Sage

Hi @Anonymous ,

 

You should be able to do this with a change or two to the measure you have currently. I've created a rough setup but the idea should work the same. 

 

Keep your time table unlinked, and create a measure like this one

Measure = 
Var _time = SELECTEDVALUE('Time Table'[Time])
Var _activity = CALCULATE(COUNTROWS('Table'), 'Table'[Start]<= _time , 'Table'[Finish] > _time)
Return
_activity + 0

The idea is to look at the current time, then count how many events are active at that time, using CALCULATE to filter the table.

 

If you add the 'Operating Theatre' field into you rows, turn off 'stepped layout' under row headers formatting and then add this measure to values

 

AntonioM_0-1661942348808.png

AntonioM_2-1661942463826.png

 

That will give you something like this

AntonioM_1-1661942392132.png

And then you can format the 1s to show colour and the 0s to be blank, as you have before.

 

 

Hope that helps, 

Any problems please let me know. 

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.