Forum Discussion

volunteersfpl's avatar
volunteersfpl
Copper Contributor
Dec 17, 2025
Solved

Calculate overlapping hours

Hello, 

I need to report how many hours a staff member supervised one or more volunteers. For a very simplified example,

Volunteer NameDateStart Time End Time Supervisor
Fred1/1/261:00pm3:00pmLucy
Ethel1/1/262:30pm4:30pmLucy

 

Here 4 volunteer hours were served, but because there was a 30 minute overlap, Lucy only supervised for 3.5 hours.  

Is there a way to get Excel to calculate that? To say: look at all the entries with matching date and matching supervisor, and add up non-overlapping time.

I'm not expecting this to be possible, but I thought I'd ask. Thanks!

  • Hi

    To help people who search for existing solutions it would be smart of you to revise the title of this thread with Calculate non-overlapping hours ;-) - Thanks

    With Power Query > Pivot Report:

    Added dummy records to those you provided. Looks good to me...

    #1 Please double-check and confirm (or not). Sample (to download) avail. at:

    https://1drv.ms/x/c/1cd824d35610aacb/IQCkJLQ4qI2hQ6OG2-ntg7wiATHCsDR7AVWdpHB_O7bJjgs?e=xn9UML

    #2 Let me know if you prefer a flat Table instead of a PivotTable Report

    How to use:
    With your data in TableData > Right-click somewhere in PivotTable Report > Refresh

    Notes:
    1) If you double-click on a number in the [Total Hours] col. of the PivotTable Report a sheet will give you the details of what made that number. However, you might get less records than in TableData as the query filters out some records for perf. reason.
    As an ex. : on 11/06/25 Freddie has 9 records but double-clicking on his 10.5 [Total Hours] for that date you get 8 records. The one that's filtered out is:

    because [Start Time] > [End Time]

    2) Also filtered out are records, where for the same [Supervisor] on a given [Date], we have duplicated [Start Time] & [End Time]

    3) With the provided sample dataset, [Supervisor] Foo isn't reported as it has only 1 record where [End Time] = [Start Time]

7 Replies

  • volunteersfpl's avatar
    volunteersfpl
    Copper Contributor

    I understand pivot tables a bit, so I'm going to go with Lorenzo​ Lorenzo's solution, but will also copy IlirU​'s code for reference--thanks to you both!

    mathetes​, for my use, there is no deeper purpose. There is a yearly report that requires an entry for how many staff hours were spent supervising volunteers, so I'm just looking for a way to report good-quality data to meet that requirement. When I set up this summer's time reporting form, volunteers will report precise times, I just rounded to 15 minutes for dummy-data purposes.  

  • mathetes's avatar
    mathetes
    Gold Contributor

    It looks to me as if Lorenzo​ has given you an effective answer. I was about to ask some more defining questions, which I will do anyway, in case his response doesn't work for you (if, for example, Power Query is a feature you haven't used and don't understand; no shame in that: I understand it, but have never used it myself).

    My questions--and I'm writing as a person who at one time was the director of the HR & compensation database for a major corporation, so these are questions I would have asked at the time of a management request for a report on time spent--get at the deeper purpose being served. Let me first refer you back to my initial response, where I asked these questions:

    • Are they only paid for time supervising?
    • Are they paid more for time supervising than time spent at work but not supervising?
    • If they're paid a straight hourly (or salary) regardless of whether time is spent supervising, do you still need to know specifically the amount of time spent supervising? Why? How is it used?

    Part of what these questions are trying to get at is this: How precise do you really need to be? You're already (it would appear) rounding times to the nearest quarter hour. Which means your total times might well deviate from reality by significant margin. Does that matter?   To ask it again: How precise do you really need to be? Would it, for example, be just as valuable, maybe more so(!), to know that Susy routinely supervises two or three people a day (regardless of hours), while Larry rarely supervises more than one? And to repeat the question above, are these staff members tracking their own time--are they paid hourly or on salary--and are they compensated differently for time spent supervising? 

    How is this summary data on hours spent supervising used? What difference does it make in your management of these staff people?

  • Lorenzo's avatar
    Lorenzo
    Silver Contributor

    Hi

    To help people who search for existing solutions it would be smart of you to revise the title of this thread with Calculate non-overlapping hours ;-) - Thanks

    With Power Query > Pivot Report:

    Added dummy records to those you provided. Looks good to me...

    #1 Please double-check and confirm (or not). Sample (to download) avail. at:

    https://1drv.ms/x/c/1cd824d35610aacb/IQCkJLQ4qI2hQ6OG2-ntg7wiATHCsDR7AVWdpHB_O7bJjgs?e=xn9UML

    #2 Let me know if you prefer a flat Table instead of a PivotTable Report

    How to use:
    With your data in TableData > Right-click somewhere in PivotTable Report > Refresh

    Notes:
    1) If you double-click on a number in the [Total Hours] col. of the PivotTable Report a sheet will give you the details of what made that number. However, you might get less records than in TableData as the query filters out some records for perf. reason.
    As an ex. : on 11/06/25 Freddie has 9 records but double-clicking on his 10.5 [Total Hours] for that date you get 8 records. The one that's filtered out is:

    because [Start Time] > [End Time]

    2) Also filtered out are records, where for the same [Supervisor] on a given [Date], we have duplicated [Start Time] & [End Time]

    3) With the provided sample dataset, [Supervisor] Foo isn't reported as it has only 1 record where [End Time] = [Start Time]

  • sophieturner's avatar
    sophieturner
    Copper Contributor

    Yes, it’s possible, but it takes a small setup. The idea is to combine all time ranges for the same date and supervisor, then calculate the total span without double-counting overlaps. In your example, Lucy’s supervision runs from 1:00pm to 4:30pm, which equals 3.5 hours. You can do this in Excel by finding the earliest start time and latest end time for each supervisor and date, then subtracting the two. This works well as long as there are no gaps in supervision time.

  • mathetes's avatar
    mathetes
    Gold Contributor

    Given that example, it's incredibly easy to calculate the 3.5 hours. Simply subtract the minimum of Lucy's start times from the maximum of her end times.

    (making assumptions about which columns contain the relevant data),
    time spent supervising =MAX(D2:D3)-MIN(C2:C3)    

    Granted, that doesn't deal with other staff members and other days; just wanted to make the point that a simple example doesn't require much complications in solving.

    But as you point out in asking the question, it's a very simplified example. Give us a more typical full day, complete with some examples that make it complicated. Along the way, can you explain the rules here that govern Lucy's (and other's) staff compensation, in particular

    • Are they only paid for time supervising?
    • Are they paid more for time supervising than time spent at work but not supervising?
    • If they're paid a straight hourly (or salary) regardless of whether time is spent supervising, do you still need to know specifically the amount of time spent supervising? Why? How is it used?

    By the way, you should expect it to be possible, whatever it is. Excel is very powerful; the challenge often is getting the problem clearly set forth and articulated. 

    • volunteersfpl's avatar
      volunteersfpl
      Copper Contributor

      Yes, the real-world situation is 300+ volunteers entering shifts across 3 summer months at 28 locations with 30-40 supervisors, and shifts aren't necessarily adjacent, so Lucy might supervise 2 volunteers from 10:00-noon, 1 volunteer from 11:30am-1pm, and then have an hour off and then have volunteers in from 3:00-5:00pm, so just taking MIN to MAX (10am-5pm) wouldn't be accurate. Some volunteers come in every day, some only once a week, but by the end of the summer, I have upwards of 10,000 rows of time entries. 

      I have had to just report volunteer hours, but now I need to report how many staff hours were spent supervising volunteers, so I would change how time is logged to have start and end time, instead of total hours. 

      This is one month of time entries at one location. Not difficult to go through and manually calculate, but time consuming at scale. 

      Volunteer Name    Date    Start Time     End Time     Supervisor
      G    5/17/2025    10:00 AM    1:15 PM    2
      L    5/17/2025    10:00 AM    12:00 PM    1
      O    6/6/2025    1:00 PM    2:00 PM    2
      O    6/9/2025    2:00 PM    4:00 PM    2
      W    6/9/2025    3:00 PM    5:00 PM    2
      T    6/10/2025    10:00 AM    12:00 PM    2
      I    6/11/2025    10:00 AM    12:00 PM    3
      S    6/11/2025    1:00 PM    3:00 PM    1
      T    6/11/2025    2:00 PM    4:00 PM    3
      T    6/12/2025    11:00 AM    1:00 PM    2
      Z    6/12/2025    11:00 AM    5:00 PM    3
      B    6/13/2025    2:00 PM    4:00 PM    2
      D    6/13/2025    1:00 PM    3:00 PM    2
      N    6/13/2025    2:00 PM    4:00 PM    2

      (wouldn't publish copied table so sorry for lack of formatting)

      • IlirU's avatar
        IlirU
        Brass Contributor

         

        Hi volunteersfpl,

        Does the following formula meet your requirements? The formula works in Excel 365.

         

        =LET(
         table, A1:D15,
             d, DROP(table, 1), date, CHOOSECOLS(d, 2),
        startt, CHOOSECOLS(d, 3), endt, CHOOSECOLS(d, 4),
            dr, DROP(GROUPBY(date, endt, MAX,, 0) * 24,, 1),
                VSTACK(HSTACK(TAKE(TAKE(table, 1),, 2), "Hours"),
                CHOOSECOLS(HSTACK(GROUPBY(date, CHOOSECOLS(d, 1), ARRAYTOTEXT,, 0),
                (BYROW(IFNA(--TEXTSPLIT(TEXTJOIN(";",, BYROW(--TEXTSPLIT(TEXTJOIN(";",,
                BYROW(IFNA(HSTACK(--TEXTSPLIT(TEXTJOIN(";",, BYROW(IFNA(--TEXTSPLIT(TEXTJOIN(";",,
                DROP(GROUPBY(date, MAP(startt, endt,
                LAMBDA(a,b, ARRAYTOTEXT(SEQUENCE(, INT((b - a) * 24), a * 24)))),
                ARRAYTOTEXT,, 0),, 1)), ", ", ";"), ""), LAMBDA(c, ARRAYTOTEXT(UNIQUE(c, TRUE))))),
                ", ", ";", TRUE), INT(dr)), ""), LAMBDA(z, ARRAYTOTEXT(SCAN(0, z, LAMBDA(a,b,
                IF(b = "", a, b))))))), ", ", ";"), LAMBDA(w, ARRAYTOTEXT(UNIQUE(w, TRUE))))),
                ", ", ";"), ""), COUNT) - 1) / 24 + MOD(dr, 1) / 24), {2,1,3})))

         

        Hope this helps.

        IlirU

Resources