Sum column if cells are outside range (range = leftmost value in row + next 11 columns) R or Excel? -


so please see picture. in matrix pictured, entry considered "new business" leftmost value + next 11 columns (so 12 months total). i've highlighted "window" in yellow. right of window "return business". each column/month, need calculate both new & return business. need formula or method derive these 2 sums 1 column. need able 1 of these, because subtract total column sum other value.

enter image description here

in cell o6 result $25 each because leftmost value on row 5 not extend full 12 months/columns before column o, within 12 month window still considered "new" (i made window blue see extends beyond cell i'm trying result for). 11 columns right of first value in row populated, still new. 13th column on considered "return.

as can see, first value in each row not occur in same spot, moves.

the spreadsheet working 2,000+ rows. went through , did manually, not fun! manually found leftmost value in each row, counted out 11 cells after it, , colored rest of row yellow. used custom function allowed me sum based on cell color. if there way conditionally format values, work too, use color sum function.

additionally, if there better way in r, please let me know. new r, imagine matrix math easier/faster do, i've played around bit , i've never had in it.

thanks help!

i added helper column c finds first non blank in row (my data went column d column az)

=match(true,index((d2:az2<>0),0),0) 

this formula put in cell d5 , copied across

=sumifs(d2:d4,$c2:$c4,">"&column(d1)-12-3) 

the 12 12 months , 3 column c data starts.

the return business in d6 , across

=sum(d2:d4)-d5 

my results


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -