Forum Discussion

saanah2019's avatar
saanah2019
Helper II
7 years ago
Solved

Calculate free time

Hi, I have an appointment table and I want to find out the times between appointments and the time there is no appointment. So I have date, datetime, starttime, endtime, duration and I want to declare a total time daily of allowable appointments of 8 hours. I think the easiest way to achieve this is to create a new column and then have it look at each day, add the duration and subtract this sum from the 8 hours and the end result would be my time between appointments.

 

datestartend datetimeduration daily appoint allowed total daily duration free time(daily - total daily duration)
1/1/201810:0010:301/1/2018 10:0030 480 115  365  
1/1/201810:4011:001/1/2018 10:3030         
1/1/201811:05121/1/2018 11:0555         
1/4/201811:0011:301/4/2018 11:0030 480 90  390  
1/4/201811:4012:401/4/2018 11:4060         
1/6/201811:00121/6/2018 11:0060 480 60  420  
1/7/201811:0011:501/7/2018 11:0050 480 150     
1/7/201812:0012:201/7/2018 12:0020         
1/7/201812:301:001/7/2018 12:3030         
1/7/201813:0513:551/7/2018  13:05:00 PM50         
              
              
              

 

 

So I have all the columns except for the last three and want to know how to achieve them in Power BI. Thank you. 

  • Hi saanah2019 ,

    Do you want to get the output below?

    If so, please create the calculated columns with the formulas below.

    daily appoint allowed = 8*60
    total daily duration = CALCULATE(SUM(Table1[duration]),ALLEXCEPT(Table1,'Table1'[date]))
    free time = 'Table1'[daily appoint allowed]-'Table1'[total daily duration]

    If you still need help, please feel free to ask.

    Best Regards,

    Cherry

     

2 Replies

  • v-piga-msft's avatar
    v-piga-msft
    Resident Rockstar

    Hi saanah2019 ,

    Do you want to get the output below?

    If so, please create the calculated columns with the formulas below.

    daily appoint allowed = 8*60
    total daily duration = CALCULATE(SUM(Table1[duration]),ALLEXCEPT(Table1,'Table1'[date]))
    free time = 'Table1'[daily appoint allowed]-'Table1'[total daily duration]

    If you still need help, please feel free to ask.

    Best Regards,

    Cherry

     

  • v-piga-msft just a quick add. what happens when there is another column and I also need to take that into consideraton.So now I would want to basically look at the names, if they are the same then look at the date, and then for all the same date sum the duration

     

                   
                   
    namedatestartend datetimeduration daily appoint allowed total daily duration free time(daily - total daily duration)
    sam1/1/201810:0010:301/1/2018 10:0030 480 60  420  
    sam1/1/201810:4011:001/1/2018 10:3030   60  420  
    kate1/1/201811:05121/1/2018 11:0555 480 55  425  
    sam1/4/201811:0011:301/4/2018 11:0030 480 90  390  
    sam1/4/201811:4012:401/4/2018 11:4060   90  390  
    kate1/6/201811:00121/6/2018 11:0060 480 60  420  
    kate1/7/201811:0011:501/7/2018 11:0050 480 70  410  
    kate1/7/201812:0012:201/7/2018 12:0020   70  410  
    sam1/7/201812:301:001/7/2018 12:3030 480 80  400  
    sam1/7/201813:0513:551/7/2018  13:05:00 PM50   80  400