How to sum individual values in Excel based on changes in other column - excel

I want to create a formula in Excel that sums values based on values in another column. The second column is based on an IF function:
=IF(K4>=$N$1,0,IF(K3<$N$1,0,1)).
Every time a set of "1" occurs, it is grouped as a single event. But now I want to sum the values that are based on this grouping. So the first set of "1" should give a total of 4 and the second set of "1" should give 5.
Is there a way to let Excel sum the first column every time the second column changes from 0 to 1, knowing that the sets of "1" in the first column is different every time?
1 0
1 0
1 0
1 1
0 0
0 0
1 0
1 0
1 0
1 0
1 1

Something like this that sums the first column to that point and subtracts the current column total to that point:
=IF(A2>A3,SUM($A$2:A2)-SUM($C$1:C1),"")

Related

How can I get the values from one column that match a given arguement and put them in another column without leaving blank cells

This is probably a simple task for most but given the following example how could I pull out the rows that have a value of greater than 0 and put them in another column without the cells that contain 0 leaving a blank row?
1
0
7
1
0
4
0
0
But I would like to achieve
1
7
1
4

How to ensure list of numbers in excel column continues from the last non zero number

Imagine 3 columns, Column A and Column B and Column C.
Column A is a date column.
Column C is lookup column that looks up a value from 1 - 100 from a different table based on the date.
Column B is continuation of values from 0 from the first date value and continues with the value until the value in column c changes.
How do you formulate column B so it automatically keeps the last non zero value until another value in column C appears?
Column A
Column B
Column C
01/01/2021
0
0
02/01/2021
0
0
03/01/2021
0
0
04/01/2021
20
20
05/01/2021
20
0
06/01/2021
20
0
07/01/2021
50
50
08/01/2021
50
0
09/01/2021
50
0
Either
=IFERROR(LOOKUP(2,1/(C$1:C1<>0),C$1:C1),0)
Or;
=XLOOKUP(TRUE,C$1:C1<>0,C$1:C1,0,0,-1)
Or, if these values are always bigger then the last one:
=MAX(C$1:C1)
You can do it as a spill formula in Excel 365 too:
=LET(range,C1:C9,
seq,SEQUENCE(ROWS(range)),
XLOOKUP(seq,IF(range>0,seq),range,0,-1)
)

I need a formula in my excel to check multiple criteria and give result in 3 ways

Actually, In my excel sheet i want to check when both values and print result example: I need answer like this 1 0 =1, 0 1 =1, 1 1 =0 How to write formula for this please help me
Given your conditions your formula in the resultant cell should be as follows
Conditions
1 0 = 1
0 1 = 1
1 1 = 1
Formula in resultant cell (can be extended to any other combinations of conditions and not using XOR as 0 0 condition is not defined)
=IF(OR(A1=0,B1=0), 1, 0)
Sample Excel Sheet

Excel sum one column based on another

I have data that is divided into columns as follows:
Runs RunsAfter Switch New
0 2 1
0 2 0
1 2 0
0 1 0
1 1 0
0 0 0
0 0 0
0 0 1
0 1 0
1 1 0
0 0 0
I want excel to sum the Runs column by taking each cell and summing down the remainder of the column until there is a 1 in the Switch column. It should then start calculating again until another Switch. All of this output should be put in the New column. The result should look like the RunsAfter column, which I am currently calculating by hand. I would keep doing this, but the dataset is going to get too big to continue doing this by hand.
I've checked for questions similar to this, but haven't been able to find quite what I'm looking for. If I've missed an answer elsewhere, please let me know.
If I am understanding correctly, I think you want to use a combination of the match formula to find the next "switch" and the indirect formula to define the range to sum. I can't think of a simple way to do this.
This is assuming that your headers are in row 1 and your columns are Runs (A), RunsAfter (B), Switch (C), and results in D. I've used 100 for your last row, but you will need to change that if you have more rows. This is what I did in D2:
To find the next row for which Switch is 1:
MATCH(1,C3:$C$100,0)+ROW()
I also included iferror to make it not break for rows after the last switch:
IFERROR(MATCH(1,C3:$C$100,0)+ROW()-1,100)
I included this as part of the indirect formula to tell it what range to sum up:
D2=SUM( INDIRECT("A"&ROW()&":A$"&IFERROR(MATCH(1,C3:$C$100,0)+ROW()-1,100)))
So for D2, it's summing from A2 to the row before the next switch, in this case row 8. You should be able to drag it down from D2 with those anchors.

Use value in cell as index for row in Excel SUM function

Given the two worksheets below, I want to put a SUM in Column F for each row but instead of SUMMING the values in Sheet1, I need to use the cell value in Sheet1 as the row number in Sheet2 and use those cell values in the SUM. For example, the SUM for Bill should be SUM(Sheet2! B1,C6,D4,E3) = 200.
Sheet1
A B C D E F
Bill 1 6 4 3 200
Sue 2 1 3 2 450
Mary 3 2 2 1 550
Joe 4 3 1 4 150
Alice 5 4 25
Bob 6 5 0
Sheet2
A B C D E
1 100 200 50 400
2 50 100 25 200
3 25 50 0 100
4 0 25 0 50
5 0 0 0 0
6 0 0 0 0
This is just a sample spreadsheet; in the real one there are already 40 columns with more being added as necessary.
In Sheet1!F1:
=SUMPRODUCT(N(OFFSET(Sheet2!$A$1,B1:E1-1+(B1:E1-1<0)*(2^20-1),COLUMN(B1:E1)-1)))
Copy downwards as necessary.
The cells Sheet2!1048576:1048576 should not have content. Because those cells will be referenced if the row number given in Sheet1 is 0 or empty.
With the data to be summed in Sheet2!A1:E6, use this formula in Sheet1's first row's column F.
=SUM(INDEX(Sheet2!B:B, B2)*SIGN(B2), INDEX(Sheet2!C:C, C2)*SIGN(C2), INDEX(Sheet2!D:D, D2)*SIGN(D2), INDEX(Sheet2!E:E, E2)*SIGN(E2))
A zero or blank in Sheet1 would mean the entire column but that is multiplied by the SIGN function of that cell's value. Anything multiplied by zero equals zero and that will not impact the overall sum.
      
Using the INDEX function with the cell's value supplying the row_num parameter allows you to avoid volatile¹ functions that would negatively impact the calculation lag of the workbook.
¹ Volatile functions recalculate whenever anything in the entire workbook changes, not just when something that affects their outcome changes.

Resources