Finding Total Duration Based on Multiple Criteria

Orion19

Board Regular
Joined
Dec 18, 2017
Messages
56
Hello all, and Thank You in advance!

A sample data set is below. I'm trying to write a formula that tells me the total session length for any given date. In the data set below, the output I'm looking for would be 5:17 (3:04 + 2:13). There are only two sessions, one from 8:29 to 11:33 and the second from 12:47 to 15:00. Projects (name and quantity), Start Times, and End Times will all vary. All of the attempts I've made have failed to recognize there are only two sessions in an example like this. Thanks again for any tips!

ProjectDateStart TimeEnd TimeSession Length
Project 1
5/18:2911:333:04
Project 15/112:4715:002:13
Project 25/18:2911:333:04
Project 25/112:4715:002:13
Project 35/18:2911:333:04
Project 35/112:4715:002:13

<tbody>
</tbody>
 
In A1:B1 of the pivot table, B1 contains a filter: you can choose for any project or for all. The pivot table shows the appropriately summed ssession length.

If this does not meet your needs, try to post a sample input along with the output you want to obtain from that input.
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Sorry, hopefully this data set makes more sense. I'm looking for formulas for G2:G3 below. Thank you!


Row/
Column​
ABCDEFG
1
Session DateSession Start TimeSession End TimeSession LengthDatesTotal Worked
21/1/181/1/18 8:131/1/18 10:502:371/1/182:37
33/26/183/26/18 7:553/26/18 11:303:353/26/185:29
43/26/183/26/18 13:033/26/18 14:571:54
51/1/181/1/18 8:131/1/18 10:502:37

<tbody>
</tbody>
 
Upvote 0
I used the dates in Column A as a reference. I didn't re-write the dates in Column F.
Don't be confused by the dates, I have used the dates as per DD/MM/YYYY as per the Indian timings. It doesn't affect the formula in any way.

Try this

ABCDEFG
1DateStartEndLength Output
201-01-201801-01-2018 08:1301-01-2018 10:5002:37 02:37
326-03-201826-03-2018 07:5526-03-2018 11:3003:35 05:29
426-03-201826-03-2018 13:0326-03-2018 14:5701:54
501-01-201801-01-2018 08:3301-01-2018 10:5002:37

<colgroup><col style="font-weight:bold; width:30px; "><col style="width:73px;"><col style="width:109px;"><col style="width:109px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"></colgroup><tbody>
</tbody>

Spreadsheet Formulas
CellFormula
G2{=SUMIF(A2:INDEX(A2:A5,MATCH(FALSE,(INT(B2:B5)=INT(B2)),0)-1),INT(B2),D2:D5)}
G3{=SUMIF(A3:INDEX(A3:A6,MATCH(FALSE,(INT(B3:B6)=INT(B3)),0)-1),INT(B3),D3:D6)}

<tbody>
</tbody>
Formula Array:
Produce enclosing
{ } by entering
formula with CTRL+SHIFT+ENTER!

<tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4
 
Last edited:
Upvote 0
Sorry, hopefully this data set makes more sense. I'm looking for formulas for G2:G3 below. Thank you!


Row/
Column​
ABCDEFG
1Session DateSession Start TimeSession End TimeSession LengthDatesTotal Worked
21/1/181/1/18 8:131/1/18 10:502:371/1/182:37
33/26/183/26/18 7:553/26/18 11:303:353/26/185:29
43/26/183/26/18 13:033/26/18 14:571:54
51/1/181/1/18 8:131/1/18 10:502:37

<tbody>
</tbody>

Looks like...

In G2 control+shift+enter, not just enter, and copy down:
Rich (BB code):
=SUM(IF(FREQUENCY(IF($A$3:$A$6=F3,MATCH($B$3:$B$6,$B$3:$B$6,0)),ROW($A$3:$A$6)-ROW($A$3)+1),$D$3:$D$6))
 
Upvote 0
Alternatively
Excel Workbook
ABCDEFG
1DateStartEndLengthOutput
201-01-201801-01-2018 08:1301-01-2018 10:5002:3702:37
326-03-201826-03-2018 14:5726-03-2018 11:3003:3505:29
426-03-201826-03-2018 14:5726-03-2018 14:5701:54
501-01-201801-01-2018 08:1301-01-2018 10:5002:37
Sheet
 
Last edited:
Upvote 0
Thank you!!! This does the trick! I think I need to develop a better understanding of MATCH, FREQUENCY, AND INDEX functions. Thank you again!

Looks like...

In G2 control+shift+enter, not just enter, and copy down:
Rich (BB code):
=SUM(IF(FREQUENCY(IF($A$3:$A$6=F3,MATCH($B$3:$B$6,$B$3:$B$6,0)),ROW($A$3:$A$6)-ROW($A$3)+1),$D$3:$D$6))
 
Upvote 0
Looks like...

In G2 control+shift+enter, not just enter, and copy down:
Rich (BB code):
=SUM(IF(FREQUENCY(IF($A$3:$A$6=F3,MATCH($B$3:$B$6,$B$3:$B$6,0)),ROW($A$3:$A$6)-ROW($A$3)+1),$D$3:$D$6))

Quick question for you again if you're available. I filled about 500 cells with appropriate variations of the formula you came up with. The values are returned correctly and the macro runs smoothly. However, if I manipulate the raw data set in any way there is a delay of over a minute before the workbook responds. For example, if I filter out a specific date or add a row it will cause the delay. I *think* it's running the array formulas again to auto update but I'm not certain. Do you have any tips? Thank you!!
 
Upvote 0
Quick question for you again if you're available. I filled about 500 cells with appropriate variations of the formula you came up with. The values are returned correctly and the macro runs smoothly. However, if I manipulate the raw data set in any way there is a delay of over a minute before the workbook responds. For example, if I filter out a specific date or add a row it will cause the delay. I *think* it's running the array formulas again to auto update but I'm not certain. Do you have any tips? Thank you!!

A huge of number of this kind of formulas can cause some delay, especially if you also have formulas around with volatile functions like INDIRECT, OFFSET.

Does the data range change often? If it does, we can work with dynamic named ranges. If you want try this route, would you post the formula as you have implemented it?
 
Upvote 0

Forum statistics

Threads
1,215,139
Messages
6,123,262
Members
449,093
Latest member
Vincent Khandagale

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top