Advanced(?): Excel formula to calculate duration based on three activity levels with reset for each change of level

skm95

New Member
Joined
Mar 29, 2023
Messages
4
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. MacOS
Hi there, I´m a master´s student who have been stuck with this issue for 10 hours now, and cant proceed with my analyzation without solving this problem... Please help me get over this.

I need help creating an Excel formula that can sum the duration (in time format hh:mm:ss) for each activity level (1, 2, and 3) as they occur in the dataset. The summary calculation should start when the activity level changes (or the dataset begin), and end when the activity level changes again. Each time the level changes, the function should start summing the duration of that row of the same levels anew, discarding the previous summary output before the level changed. The goal is to have a function that can accurately calculate the total time spent on each activity level in the dataset as they occur after each other.

Let me provide an example using a small part of my dataset as attached.
For example, as row 2 to row 13 contain the same activity level (2), but row contain activity level 3. The total duration from row 2-13 needs to be summed in a new column. The same goes with row 14 to row 15, which is of activity level 3, and needs to be summed together as the row below has another activity level, and so on... When in row 16 changes back to level 2, the calculation should start from scratch where the duration time is 00:15:17 as there is only one row of level 2.
I am having trouble understanding how to create this function, and would greatly appreciate any help as all functions I have tried is unsuccessful...

PS: i cannot change the order of the rows as this will take away the whole point

Screen Shot 2023-03-30 at 02.13.22.png
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Upvote 0
Hi, thanks for your answer. No, not exactly. When in row 16 the level is changing from 3, back to level 2, the calculation should be reset, so instead of the duration sum of 03:19:05, it should be 00:15:17 as there is only one row with level 2. Each time the activity level is changed back, the sum should start at 0, not continue from the previous duration summary.
 
Upvote 0
Upvote 0
Solution
I think that makes it simpler (@Fluff just beat me to it :ROFLMAO: )
skm95.xlsx
ABCD
1RowDurationActivity LevelsThis maybe?
2100:15:16100:15:16
3200:15:16200:15:16
4300:15:17200:30:33
5400:15:16200:45:49
6500:15:16201:01:05
7600:15:17201:16:22
8700:15:16201:31:38
9800:15:16201:46:54
10900:15:17202:02:11
111000:15:41202:17:52
121100:15:24202:33:16
131200:15:17202:48:33
141300:15:15203:03:48
151400:15:17300:15:17
161500:15:15300:30:32
171600:15:17200:15:17
181700:15:16300:15:16
Sheet3
Cell Formulas
RangeFormula
D2:D18D2=IF(C2<>C1,B2,B2+D1)
 
Upvote 0
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
wow, thats great guys! just what i needed. Thank you so much, this made my day.
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
Ok, I will remember that next time. Thank you for letting me know.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
I ended up using this formula:
=IF(C2=C3;"";SUMIF($C$1:C2;C2;$B$1:B2)-SUMIF($C$1:C1;C2;$D$1:D1))
as it returns a blank in the columns, I do not need to be summed.

It´s very nice to see the different aspects of how this can be done. I appreciate your help.
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,177
Members
452,615
Latest member
bogeys2birdies

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