Sum the values of if statements on multiple rows? (Excel) - excel

Say I have a spreadsheet which looks like this:
A B C
1 In Actual Predicted
2 Thing One 300
3 Thing Two 564
4 Thing Three 256 1065
I want to be able to get a sum of the "predicted" column which incorporates values from the "actual" column if the "predicted" value is empty.
I.e. in this case, the value would be 300 + 564 + 1065 = 1929.
I know that I can achieve this for any individual row like so:
IF(C2="",B2,C2)
How do I get a sum of these "if" statements for each individual row?
Thanks.

That can be done with Sumifs() and no helper columns
=SUMIFS(B:B,C:C,"")+SUM(C:C)

Cell D2 = IF(C2="",B2,C2)
Cell D3 = IF(C3="",B3,C3)
...drag / copy to all relevant D cells...
Cell E1 = Sum(D:D)

Related

Finding rows where col A & B match and sum of col C = 0

Hi all,
I am looking for a way to find rows under the following conditions:
Values of column A matches, values of column B matches AND values of column C add to 0.
I've tried sumproduct on conditional formatting without much success.
=SUMPRODUCT(($C$1:$C$9)*($A$1:$A$9=$A1)*($B$1:$B$9=$B1))=0
Perhaps VLOOKUP could be used? Any suggestion would be appreciated!
I'm using two helper columns. You could hide these in your spreadsheet. Col E = colA & colB. Col F has this formula:
SUMIFS(C$1:C$8, E$1:E$8, E1) = 0
This says if the sum of values in col C = 0 where col E matches the current row, TRUE, otherwise FALSE.
Then I added a conditional rule for A1:C8 to highlight in yellow. The rule is
=$F1
This says to highlight the row if the col F is true for that row. I think this will do what you want.
Note that my highlighted results are different than yours. You show 2 rows of 1015 in Col A + B in Col B as highlighted. Why would this be? (50) + 50 + 50 does not = 0? (Thanks to Jerry J for pointing this out.)
Maybe someone more clever than I can figure out how to do it without helper columns. Until then, here is one way to do it:
You need just one helper column - a column that does a running total for each value of A and B. So, put this in D2 and copy it down all the way to D9:
=SUMIFS($C$2:$C2,$A$2:$A2,$A2,$B$2:$B2,$B2)
That will sum all the values above the current cell that have the same A and B. What that does is find where the rows finally sum to zero.
Then you can use this in your conditional formatting:
=COUNTIFS($D2:$D$9,0,$A2:$A$9,$A2,$B2:$B$9,$B2)
That will find the zero below the current cell that has the same A and B. So, it doesn't include cells that have the same A and B that are below the 0.
If you put that second formula in E2 and copy it down all the way to E9 it looks like this:
A
B
C
D
E
Deal
Item
USD
Running Total
Conditional Formatting
1010
A
100
100
1
1015
A
-100
-100
0
1010
A
-99
1
1
1010
A
-1
0
1
1010
B
-100
-100
0
1015
B
-50
-50
1
1015
B
50
0
1
1015
B
50
50
0
If it's not a huge table and you want all rows where A and B match, try this:
=SUMIFS($C$2:$C$9, $A$2:$A$9, A2, $B$2:$B$9, B2) = 0
Or, if you highlight your rectangle and Insert - Table then make a new column with a formula of
=SUMIFS([USD], [Deal], [#Deal], [Item], [#Item]) = 0
then use that column for your conditional formatting formulas and, if you wish, hide the column. That way it's easier to read, you only need to enter the formula once instead of dragging it down the column, and it will store it once instead of once per row.
If it is a huge table then you are going to want to make a pivot table and then use that, because executing this for every row in your raw table will probably be a lot slower than a pivot table would, but using a pivot table is less user-friendly because the changes aren't instant unless you do some VBA to refresh the pivot table anytime something changes.

Excel Function to sum values from table based on a comma separated list

I am trying to find a function that will look at a table and sum all the values where the string appears in my comma separated list. I can get sumproduct to work if my list is separated into different cells, but I need the list to be in one cell. Here is what I'm looking for:
List in Cell A1: 2000,2100,2300
Table: A10:B16
A B
2000 20
2100 25
2200 32
2300 65
2400 72
2500 12
2600 2
I'm looking for a result of: 110
Any help would be appreciated.
Thanks!
I am assuming that you can use another column but not for your list?
If so you can use the formula below in column C
=IF(ISERROR(FIND(A2,$A$1,1))=FALSE,TRUE,FALSE) with A2 being the 1st cell in which the data is contained.
This is searching through your comma separated list and evaluating against the data in column B whether it exists in the list, if so then returns true if not false.
Now you can use the SUMIF function to return those matching true in your new column C.
=SUMIF(C2:C8,TRUE,B2:B8)
If having the evaluation column C is a problem for other users you could always hide it

Sum the values in Excel cells depending on changing criteria

In an Excel spread sheet I have three columns of data, the first column A is a unique identifier. Column B is a number and column C is either a tick or a space:
A B C
1 d-45 150 √
2 d-46 200
3 d-45 80
4 d-46 20 √
5 d-45 70 √
Now, I wish to sum the values in column B depending on a tick being present and also relative to the unique ID in column A. In this case rows 1 and 5. Identifying the tick I use
=IF(ISTEXT(C1),CONCATENATE(A1))
&
=IF(ISTEXT(C1),CONCATENATE(B1)).
This leaves me with two arrays of data:
D E
1 d-45 150
4 d-46 20
5 d-45 70
I now want to sum the values in column E depending on the ID in column D, in this case row 1 and 5. I can use a straight forward SUMIFS statement to specify d-45 as the criteria however this unique ID will always change. Is there a variation of SUMIFS I can use?
I also wish to put each new variation of ID number into a separate header with the summed totals underneath, that is:
A B
1 d-45 d-46
2 220 20
etc...
You can try this:
To get the distinct ID's write (in H1 then copy right):
This one is an array formula so you need Ctrl Shift Enter to enter the formula
=INDEX($A$1:$A$5;SMALL(IF(ROW($A$1:$A$5)-ROW($A$1)+1=MATCH($A$1:$A$5;$A$1:$A$5;0);ROW($A$1:$A$5)-ROW($A$1)+1;"");COLUMNS($A$1:A1)))
Now to get the sum (H2 and copy right)
=SUMPRODUCT(($A$1:$A$5=H1)*ISTEXT($C$1:$C$5)*$B$1:$B$5)
Data in the example is in A1:C5
Depending on your regional settings you may need to replace ";" field separator by ","
Try this,
SUMIFS
=SUMIFS(B1:B5,A1:A5,"=d-45",C1:C5,"<>")
where "<>" means that the cell is not empty...

Count data if row is true excel

I have this Data:
var number
a 1
a 4
a 30
b 4
b 50
b 6
b 4
ab 1
I need to find the sum of each time a (var occurs X the number next column right) in excel.
In the case above the answer would be:
a = 36
b = 65
How can I write a formula for this in excel? Can I do this in excel?
Since you are counting the last one as well, I would use this formula:
=SUMIF(A:A,"*"&D2&"*",B:B)
Here, there is the value a in cell B2 and I can drag the formula down for B instead of typing a whole new formula. Handy if you have many like those to look for.
I assume that you have the table you published above in cells A1:B8. In order to do the calculating you would like to do you need to use the array-functionality in Excel. The following syntax in a cell will do:
=SUM(IF("a"=A1:A8,B1:B8))
However, instead of ENTER you need to press COMMAND+SHIFT+ENTER (I am on a Mac so it might be that Windows has a slightly different key combo. The result is that the formula now reads like:
{=SUM(IF("a"=A1:A8,B1:B8))}
This will give you 35 and not 36, but in a similar manner you could sum all the columns with 'ab' and then add that up to the sum of the 'a' columns.
Good luck!

How can I find the median of the difference of two rows?

I have two rows in two different sheets in Excel. Each row has 20 elements. I need to find the median of the difference of the corresponding elements in these two rows. I want this output to be in just one cell. I don't want to add another row in my result.
I have:
If Row1 = p1 p2 p3.... p20
If Row2 = q1 q2 q3.... q20
I need:
result cell = Median of ((p1 - q1), (p2-q2)....(p20-q20))
{=MEDIAN(P1:P20-Q1:Q20)}
This is an array formula you have to validate with Ctrl + Shift + Enter
[EDIT] Including brettdj's suggestion from the comments below, you can try this formula too:
{=MEDIAN(Sheet2!A2:T2-Sheet1!A1:T1)}

Resources