Formula until condition met

G

GBExcel

How can I SUMIF subject to each successive previous cell's value being less
than the value of the former cell?

I'm using a COUNTIF formula to determine the number of entries in each column.
The table looks something like this:

V2A: 10 20 5 10 5 10 where "V2A" stands for "Value to Add."
CI: 2 6 4 1 3 5 where "CI:" stands for "COUNT IF" values.

R1: x x x x x x where "R" stands for "ROW" as in "ROW 1:"
R2: x x x - x x where "x" stands for a value in a cell.
R3: - x x - x x where "-" stands for an empty cell.
R4: - x x - - x
R5: - x - - - x
R6: - x - - - -
Res: 0 10 0 0 10 20 where "Res:" stands for "Results."

Explanation:
I am looking for a formula that will calculate the results row, (the "Res:"
row). I have 31 columns, so nested IF statements probably won't work.

I used COUNTIF to determine the values to the right of CI. The formula that I
need must SUM the V2A values if the CI values to the columns in coluleft are
lower thanmns to the right. Therefore, the result in column 1 is '0' because
there is no value to the left of the column. The result in column 2 is 10,
because its CI value of 6 is greater than the value of 2 from the column to
its left. The results of columns 3 and 4 are 0 because the columns to their
left are greater. Notice that since the 2nd column has a greater value than
those to its left, (column 1), column 1's value is not SUMmed in formulas to
the right of column 2. The result in column 5 is 10, because the row to the
left has a lesser CI value. The result for column 6 is 20, because it is
greater than the previous 3 columns CI values, but less than column 2's CI
value.

This problem has been driving me nuts! Any help would be appreciated.
 
B

barry houdini

Hello GBExcel, Not sure what happens when the values are equal.....bu
assuming "V2A" values are in A1:AE1 and COUNTIF formulas underneath i
A2:AE2 then at the bottom of your table, say row 10, in A10 put zero an
then in B10 copied across try this formula

=SUM(INDEX(1:1,IF(COUNTIF($A2:A2,">"&B2),LOOKUP(2,1/($A2:A2>B2),COLUMN($A2:A2)))+1):B1)-B
 
G

GBExcel

Wow! That was a quick reply!

Thank you. I will try and see what happens. Will post feedback for the
benefit of others.

When the values are equal, to the left of, and less than the column being
calculated, all V2A's of the equal columns get added to the column being
calculated, on condition that there is not a column with a higher CI value
than the column being calculated in between the columns to the left.

GBExcel
 
G

GBExcel

Hi Barry,

Your formula ends with "-B" Is that correct? As opposed to "-B" with a number
as in "-B1"?

Appreciate the help.
 
B

barry houdini

Yes that's B1 at then end...I presume that got cut off somewhere, I ca
see it when I view my post......
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top