View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
MyVeryOwnSelf MyVeryOwnSelf is offline
external usenet poster
 
Posts: 213
Default Sum on a count of 45

I have information that looks like this.

Name1 Name2 Name3
Wed 11/01 N 0 1
Thu 11/02 N 1 0


It has the name going across and the date down the side. You can
ignore the N that is a seperate column that is used. What I need to
do is for a given date lets say 5/1, I need to count back 45 0's or
1's, and sum that amount. The problem is not everyone has a count for
that day. Any suggestions or how I can find out what date I have to go
back to find a count of 45 so I can sum off of that date?


Can't think of a clever way to do the calculation, but here's a brute-
force way with three "helper" columns.

Suppose C2 is the top cell in the list of 0's or 1's, with some empty
cells interspersed. Starting with columns D, E, and F all blank, put
these formulas in:

D2: =IF(C2="","",C2)

D3: =RIGHT(D2&C3,45)
and copy down far as many rows as needed

E2: =C2

E3: =E2+N(C3)-IF(LEN(D2)=45,LEN(C3)*VALUE(LEFT(D2,1)))
and copy down far as many rows as needed

F2: =IF(LEN(D2)=45,E2,"")
and copy down far as many rows as needed

Repeat this for each "Name" column. You can hide the helper columns or
use different sheets for them. Doubtless, there's a way to use fewer
columns, but I tried to keep it easy to understand.

Explanation:

Column D is a string that tracks the most recent 45 non-empty 0/1 values.
Newer ones enter on the right and older ones exit on the left.

Column E keeps a running sum, adding each value that enters and
subtracting each value that exits.

Column F echoes column E but starts when there are 45 values to count.

If there might be spurious characters in the cells, some extra cleanup in
the formulas might be needed; for example,
=LEFT(TRIM(C3))
instead of just C3.