Summing up totals for unique items.

Mogomra

New Member
Joined
Dec 5, 2004
Messages
6
I have a basic timesheet layout with the following columns: Activity, Start, End, Duration. I also have totals row at the bottom that only sums up the total duration. This little table, with its headings, is repeated 5 times on the page/sheet (vertically, for now) to give me the daily breakdown of each week.

What I am trying to do is use formulas to basically automate the process of summing up the total duration for each unique activity for each day and/or the entire week. Activities will definitely be repeated.

Now, I can do it manually in a couple of steps by myself by using advanced filter and sumproduct, but I am sharing this sheet with my coworkers, who will not be able to handle this. Therefore, I am trying to automate/"idiot proof" everything, so all they have to do is enter the activity, the start time, and the end time, and the sheet will calculate how long they did each thing and then give a summary of how much time they spent on each activity.

One of the other things I also did was to create an additional column which would identify whether or not the corresponding activity was unique or not, and then I could run an autofilter and show only unique items. This works well, except I can only do one day at a time. Also, for some reason some of the more "advanced" formulas wouldn't fill down when a row was inserted (which it will be).

I initially struggled with finding a formula for getting unique activities, but I "stole" one from another thread on this board, and it works (except for blank cells I get 0's and #N/A's, which are easily dealt with):

{=INDEX(A6:$A$18,MATCH(0,--ISNUMBER(MATCH(A6:$A$18,$H$5:H5,0)),0))}

Unfortunately, I don't know what the "--isnumber" portion is really doing here (especially the "--" prefix). I know what the function ordinarily does, but I'm a little confused as to how it's used here. If someone could explain it, that would be great.

But anyway, could any of you gurus help me out with my problem. To recapitulate, I am trying to create a function that would create a summary of the time spent on each unique activity. Since the tables/lists are dynamic, the formula (or vba) would have to adjust for any inserted rows. I've played around with dynamic named ranges and used the formula above, except it didn't go quite as planned because anytime I would insert a few rows, the formula would copy down for a couple of them, but not all, which was very annoying.

Any and all help would be appreciated. Thanks.

PS: The HTML sheetmaker wouldn't work on my computer for some reason, so I couldn't copy my screen. However, it is a very simple sheet.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hi Mogomra:

As far as the use of -- is concerned, it is a double negation operator and it is used as a coercer. The use of ISNUMBER function results in Logical True and False, and the coercer turns the TRUE and FALSE into numerics 1 and 0 respectively. Other commonly used coercers used are +1 and *0, but the use of -- is considered to be a little faster.

In regards to your main question, it would help if you can post some sample data along with your expected results so we can clearly see what you are working with and then let us take it from there.
 
Upvote 0
Sure, here's an example of the table:

Sunday 12/5/2004

Activity Start End Duration
Eating 8:00 AM 9:00 AM 1:00
Sleeping 9:00 AM 11:00 AM 2:00
Eating 11:00 AM 12:00 PM 1:00

Total 4:00


Basically this kind of table would be repeated for each day of the week. I would like to create addition tables that would list the unique activities for each day and the total hours of each, for example:

Eating 2:00
Sleeping 2:00

With that, I'm sure I could create a weekly summary using the sorted lists of unique items.

Let me know if you need additional clarification.
 
Upvote 0
Book14
ABCDEFGHIJ
1Sunday12/5/20042
2GrandTotal4:00
3ActivityStartEndDuration0ActivityTotal
4Eating8:00AM9:00AM1:001Eating2:00
5Sleeping9:00AM11:00AM2:002Sleeping2:00
6Eating11:00AM12:00PM1:00   
7
Sheet1


Formulas...

E3 must house a 0.

E4, copied down:

=IF((A4<>"")*ISNA(MATCH(A4,$A$3:A3,0)),LOOKUP(9.99999999999999E+307,$E$3:E3)+1,"")

I1:

=LOOKUP(9.99999999999999E+307,E:E)

I4, copied down:

=IF(ROW()-ROW(I$4)+1<=$I$1,LOOKUP(ROW()-ROW(I$4)+1,E:E,A:A),"")

J2:

=IF(N(J4),SUM(OFFSET(J4,0,0,MATCH(9.99999999999999E+307,J:J),1)),"")

J4, copied down:

=IF(I4<>"",SUMIF(A:A,I4,D:D),"")
 
Upvote 0
Thanks, I'll give it a shot when I get a chance.

BTW, what's all that 9.99999e+307 for? I've seen you use that before in other formulas (I think they were all for unique items) and was wondering how that worked.
 
Upvote 0
MrExcelReply.xls
ABCDEFGH
1Sunday05/12/20042
2GrandTotal04:00
3ActivityStartEndDurationActivityTotal
4Eating8:00AM9:00AM01:00Eating02:00
5Sleeping9:00AM11:00AM02:00Sleeping02:00
6Eating11:00AM12:00PM01:00  
7  
8  
9 
Sheet1


Or Try :

Cell F1, enter :

=SUMPRODUCT((A4:A100<>"")/COUNTIF(A4:A100,A4:A100&""))

Cell E4, enter and copied down :

=IF(ROW()-ROW(F$4)+1<=$F$1,LOOKUP(2,1/(COUNTIF($A$4:$A$100,F$2:F2&"")=0),$A$4:$A$100),"")

Cell G2, enter :

=IF(N(G4),SUM(G4,INDEX(G:G,MATCH(9.99999999999999E+307,G:G))),"")

Cell G4, enter and copied down :

=IF(F4<>"",SUMIF(A:A,F4,D:D),"")

Regards
 
Upvote 0
bosco_yip said:
...
Or Try :

Cell F1, enter :

=SUMPRODUCT((A4:A100<>"")/COUNTIF(A4:A100,A4:A100&""))

Cell E4, enter and copied down :

=IF(ROW()-ROW(F$4)+1<=$F$1,LOOKUP(2,1/(COUNTIF($A$4:$A$100,F$2:F2&"")=0),$A$4:$A$100),"")

Cell G2, enter :

=IF(N(G4),SUM(G4,INDEX(G:G,MATCH(9.99999999999999E+307,G:G))),"")

Cell G4, enter and copied down :

=IF(F4<>"",SUMIF(A:A,F4,D:D),"")

Regards

I don't see the need for an expensive (slow) set up...
 
Upvote 0
Aladin Akyurek said:
bosco_yip said:
...

I don't see the need for an expensive (slow) set up...

Hi Aladin Akyurek,

May I have you explanation in the comment of my set up is expensive and slow

By, this formula :

=IF(ROW()-ROW(F$4)+1<=$F$1,LOOKUP(2,1/(COUNTIF($A$4:$A$100,F$2:F2&"")=0),$A$4:$A$100),"")

In replaced of this two formula :

=IF(ROW()-ROW(I$4)+1<=$I$1,LOOKUP(ROW()-ROW(I$4)+1,E:E,A:A),"")

=IF((A4<>"")*ISNA(MATCH(A4,$A$3:A3,0)),LOOKUP(9.99999999999999E+307,$E$3:E3)+1,"")

I would like to know why and improve myself in the future.

Regards
 
Upvote 0
bosco_yip said:
Aladin Akyurek said:
bosco_yip said:
...

I don't see the need for an expensive (slow) set up...

Hi Aladin Akyurek,

May I have you explanation in the comment of my set up is expensive and slow

By, this formula :

=IF(ROW()-ROW(F$4)+1<=$F$1,LOOKUP(2,1/(COUNTIF($A$4:$A$100,F$2:F2&"")=0),$A$4:$A$100),"")

In replaced of this two formula :

=IF(ROW()-ROW(I$4)+1<=$I$1,LOOKUP(ROW()-ROW(I$4)+1,E:E,A:A),"")

=IF((A4<>"")*ISNA(MATCH(A4,$A$3:A3,0)),LOOKUP(9.99999999999999E+307,$E$3:E3)+1,"")

I would like to know why and improve myself in the future.

Regards

=LOOKUP(2,1/(COUNTIF($A$4:$A$100,F$2:F2&"")=0)

is far too slow, compared to the 2 formulas of the original set up. Moreover, the original formulas are dynamic, that is, not bound to a fixed range.

=SUMPRODUCT((A4:A100<>"")/COUNTIF(A4:A100,A4:A100&""))

which cannot never beat the speed of the formula in the original set up and locked up to a fixed range.

The foregoing answers, I might hope, the why part of:

"I would like to know why and improve myself in the future."

I appreciate that you appreciate the set up I outlined. But try not to miss its point: It's dynamic and it trades off cell space (memory) against speed (time).
 
Upvote 0

Forum statistics

Threads
1,224,516
Messages
6,179,231
Members
452,898
Latest member
Capolavoro009

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