Forum Discussion

stribor45's avatar
stribor45
Post Prodigy
1 year ago
Solved

Build Availability Table

Is it possible to build availability table of this data so you can see when there is a time in a week when there are no activities.

 

ParticipantTrainingTimeTimeDay 1Day 2
Participant 1Driving7:00:00 PM20:00:00MW
Participant 1Swimming8:00:00 AM9:00:00MW
Participant 2Basketball6:00:00 PM20:00:00TuTh
Participant 2Running11:00:00 AM13:00:00FF
Participant 3Basketball6:00:00 PM20:00:00TuTh
Participant 3Running11:00:00 AM13:00:00FF
Participant 4Basketball6:00:00 PM20:00:00TuTh
Participant 5Swimming8:00:00 AM9:00:00MW
Participant 5Walking12:00:00 PM14:00:00WF
Participant 6Driving7:00:00 PM20:00:00MW
Participant 6Basketball6:00:00 PM20:00:00TuTh
Participant 7Driving7:00:00 PM20:00:00MW
Participant 8Driving7:00:00 PM20:00:00MW
Participant 9Walking12:00:00 PM14:00:00WF
  • Hi stribor45 ,

    Certainly.  You can add a 30 minutes bucket field in the time table:

    TimeTable = 
    ADDCOLUMNS(
        GENERATESERIES(0, 1439, 1),
        "Time", TIME(INT([Value] / 60), MOD([Value], 60), 0),
        "Hour", INT([Value] / 60),
        "Minute", MOD([Value], 60),
        "Hour-Minute", FORMAT(TIME(INT([Value] / 60), MOD([Value], 60), 0), "hh:mm"),
        "30-Minute Bucket", 
            FORMAT(
                TIME(INT([Value] / 60), 
                IF(MOD([Value], 60) < 30, 0, 30), 0), 
                "hh:mm"
            )
    )
    
    

    Then write a measure like below:

    Participants during Duration 30Min = 
    VAR SelectedTime = MAX('TimeTable'[Time]) // Assume Time is in "HH:MM" format
    VAR BucketStart = TIME(HOUR(SelectedTime), IF(MINUTE(SelectedTime) < 30, 0, 30), 0)
    VAR BucketEnd = IF(MINUTE(SelectedTime) < 30, 
                       BucketStart + TIME(0, 30, 0), 
                       BucketStart + TIME(1, 0, 0))
    
    // Concatenate participants within the time window
    VAR ParticipantsList = 
        CONCATENATEX(
            FILTER(
                DISTINCT('Table'),
                'Table'[Start Time] <= BucketEnd &&
                'Table'[End Time] >= BucketStart
            ),
            RIGHT('Table'[Participant], 1),
            ", "
        )
    
    // Return either the list of participants or '〇' if no participants
    RETURN
        IF(
            ISBLANK(ParticipantsList),
            "-", // Display "-" when no participants
            ParticipantsList
        )
    

    You can use the measure above alongside a color measure in conditional formatting to achieve a visualization shown at the bottom.

    Color = 
    IF ([Participants during Duration 30Min]="-","#90EE90","#FF0000")
    //the color can be replaced with hexadecimal codes like #6B2328)))

     

    I have attached an example pbix file for your reference.

    Best regards,

     

     

20 Replies

  • Hi stribor45 As I can understand that you want to manage and visualize the availability of participants' activities throughout the week. You can create a availability table with time slots as rows and days of the week as columns.

     

    The process involves creating a disconnected time table and a calendar table, then create measure to check if an activity is occurring at specific times and days.

    To create a Calendar table, try this code:

    CalendarTable = 
    ADDCOLUMNS (
        CALENDAR ( DATE ( 2024, 1, 1 ), DATE ( 2024, 12, 31 ) ),
        "Weekday", WEEKDAY ( [Date], 2 ),
        "DayNameShort", SWITCH (
            WEEKDAY ( [Date], 2 ),
            1, "M",
            2, "Tu",
            3, "W",
            4, "Th",
            5, "F",
            6, "Sa",
            7, "Su"
        )
    )

    Table look like this:

    To create a time table, try this code:

    TimeTable = 
    ADDCOLUMNS (
        GENERATESERIES ( TIME ( 0, 0, 0 ), TIME ( 23, 30, 0 ), TIME ( 0, 60, 0 ) ),
        "TimeText", FORMAT ( [Value], "hh:mm AM/PM" )
    )

    Table look like this:

    Finaly the measure, evaluates available or not. Try below code:

    IsActivity = 
    VAR CurrentTime = SELECTEDVALUE ( TimeTable[Value] )
    VAR CurrentDay = SELECTEDVALUE ( 'CalendarTable'[DayNameShort] )
    RETURN
    IF (
        COUNTROWS (
            FILTER (
                Activities,
                ( Activities[Day 1] = CurrentDay || Activities[Day 2] = CurrentDay ) &&
                CurrentTime >= Activities[Start Time] && CurrentTime <= Activities[End Time]
            )
        ) > 0,
        "Not Available",
        "Available"
    )

    Final output(s):
    Output Version 1:

    Output Version 2:

    Output Version 3:

     

    All tables are disconnected. So, without place measure in value field it will show error. After place measure, it will work correctly.

     



    Hope this helps!!

    If this solved your problem, please accept it as a solution and a kudos!!

     

    Best Regards,
    Shahariar Hafiz

    • stribor45's avatar
      stribor45
      Post Prodigy

      shafiz_p  can you share the file please if possible. what does the fact table look like. did you change anything?

      • shafiz_p's avatar
        shafiz_p
        Super User

        Same as you provide data. Just changed First Time column to start time and second time column to End time. See fact table image:

         

        Hope this helps!!

  • Hi stribor45 

     

    Questions:

    • What output do you expect from this sample data?
    • What is the difference between the two time column other  than having different formats  (12 vs 24 hr format?)?
    • No activities for the whole table or by participant?
    • stribor45's avatar
      stribor45
      Post Prodigy
      1. Not sure at this point.  Maybe a table where row would be time slows and column with be weekdays. 

      2. Beside being misformatted nothing. 6:00:00 PM 20:00:00 should be 6pm to 8pm and so on
      3. For the whole table
      • danextian's avatar
        danextian
        Super User

        How would you know which times are vacant if an activity does not indicate its duration?

  • Would it be easier to count how many participant are starting at same slots

     

    On Mondays  8am 2 participants

    On Mondays 7pm 4 participants

    ...

    Say if i wanted to cancel a class and set that same class for some other time slots how many participants would be affected. 

  • Hi stribor45,

    In order to solve your problem, I have created a data model like below:

     

     

    Your fact able has a relationship with the weekday table.  On the other hand, the time table, generated from the following dax table function remains a disconnected table from your fact table.

     

    TimeTable = 
    ADDCOLUMNS(
        GENERATESERIES(0, 1439, 1),
        "Time", TIME(INT([Value] / 60), MOD([Value], 60), 0),
        "Hour", INT([Value] / 60),
        "Minute", MOD([Value], 60),
        "Hour-Minute", FORMAT(TIME(INT([Value] / 60), MOD([Value], 60), 0), "hh:mm")
    )
    

    As you mentioned that the two weekday columns represent separate dates rather than a duration, I have unpivoted them to create a single weekday column. This column is now connected to the weekday dimension table, as shown above.

     

    The duration of participants' activity during the week can be visualized using the DAX measure below:

    Activity Duration = 
    VAR SelectedTime = MAX('TimeTable'[Time]) // Assume Time is in a format like "HH:MM"
    
    RETURN
        SUMX(
            'Table',
            IF(
                'Table'[Start Time] <= SelectedTime
                    &&  'Table'[End Time] >= SelectedTime,
                // Calculate the duration using max and min datetime in minutes
         1,blank()
            )
        )
    

     From the above, you can visualize the availability schedule, indicating time slots where everyone can attend—shown by the absence of any highlighting.

     I have attached an example pbix file for your reference.

    Best regards,

     

    • stribor45's avatar
      stribor45
      Post Prodigy

      I will look at this as well and let you know. thank you