Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

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

 

 

 

 

 

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

 

 

 

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  😄

 

 

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

 

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

  • 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

     

     

    That will give you something like this

    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. 

     

6 Replies

  • 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:

    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:

     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

    • elendil5259's avatar
      elendil5259
      Frequent Visitor

      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!

      • TomMartens's avatar
        TomMartens
        Icon for Super User rankSuper User

        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

  • AntonioM's avatar
    AntonioM
    Icon for Solution Sage rankSolution 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

     

     

    That will give you something like this

    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. 

     

  • Anonymous's avatar
    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

  • elendil5259's avatar
    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!