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

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.

Related

Highlight cells based on the value of cells in another column

I have this problem as noted below:
Column A = Part number
Column B = Quantity
Column C = Part number
Column D = Quantity
Using conditional formatting, I would like to highlight if the combination of Part number and Quantity in Column A and B is different to the combination of Part number and Quantity in Column C and D.
Eg:
Col A Col B Col C Col D
1 1111 2 1112 5
2 1112 3 1111 2
3 1131 5 1112 5
4 1122 3 1131 2
To do this, I'd like to set up a couple of 'helper' columns (say E & F) by concatenating Column A & B, C & D.
So essentially, I'd like to take the information from the helper columns E & F, but use conditional formatting to highlight the cell in column B and D.
From the example above, cell B3 and D4 would be highlighted.
Is this possible, and if not, is there are simple alternative? (I don't mind using a macro if need be).
I would use COUNTIFS
For B1:B4
=COUNTIFS($C$1:$C$4,A1,$D$1:$D$4,"<>"&B1)
and for D1:D4
=COUNTIFS($A$1:$A$4,C1,$B$1:$B$4,"<>"&D1)
In case you even want to skip the helper columns, you could format A1 with =$A1&$B1<>$C1&$D1 and copy the format to any cells in you want to be highlighted (even to your helper columns).

How to select certain rows in Excel that meet logical criteria of A & B

I have an excel sheet in CSV that has 8 columns A-H and thousands of rows with values 0 or 1 depending on truth value.
I'm looking for the Excel function in which I can select rows where column A and B are true so that I can check another columns probability given A&B. IE P((A&B)|D) (where | means given).
I'm really new to excel and having difficulties finding how to only select rows that meet this criteria.
The following formula entered in I1 will return a 1 if both A1 and B1 are true.
=IF(AND($A1=1,$B1=1),1,0)
Copy it down or autofill to identify all rows where A and B are true.
The $ sign before A and B make the column references absolute meaning if you drag the formula to the right, the references to columns A and B will remain.
Because Excel implicitly interprets 0 = FALSE and 1 (or any other number) = TRUE the formula could be shortened to:
=IF(AND($A1,$B1),1,0)
The probability of C being 1 given that A and B are 1 can be calculated by counting all rows where A, B and C are all 1 and dividing by the number of rows where both A and B are 1:
=COUNTIFS($A:$A,"1",$B:$B,"1",C:C,"1")/COUNTIFS($A:$A,"1",$B:$B,"1")
Again, references to A and B are absolute, while C is relative so you can drag right to get probabilities for columns D to H.
COUNTIFS only counts the rows where all of the criteria are met and allows you to specify up to 127 range/criteria pairs.
EDIT
You could also use:
=AVERAGEIFS(C:C,$A:$A,1,$B:$B,1)
to get the probability.

Sum the values of if statements on multiple rows? (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)

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...

How to format rows to color group by like values in column 1

I have a worksheet that has information like this:
a
a
b
c
c
c
How do I format it so that all of the rows that have a value of a in the first column are one color, then all the rows that have a value of b in the first column are a different color, etc. ?
Edit not from OP to add clarification from comment:
Everything is already sorted alphabetically, and will stay that way, and I want multiple colors.
Create a helper column with a formula like this;
=MOD(IF(A3=A2,0,1)+B2,2)
In this example column A is the column of sorted values to be grouped by, and column B is the helper column. The formula is entered on row 3. Set the first row of the helper column to the value 0 and the others to the formula. This will result in alternating values in the helper column for each group, ie;
a 0
a 0
b 1
c 0
c 0
c 0
d 1
d 1
e 0
You can then set conditional formatting based on the column value. If the value is 1 then highlight the row; if it is 0 do not highlight it. Or use alternating colors or whatever. You can reference any of the articles on the web that describe how to conditional format the entire row based on the value in the column.
IF(A3=A2,0,1) compares the current row (3) and prior row (2) returning a 1 or 0.
MOD( [...] +B2,2) accomplishes the alternation between 0 and 1 when the grouping column value changes.
I think you need a helper column, say B seeded with 1 in row1, and =IF(A1=A2,B1,B1+1) in B2 and copied down to suit. Then formulae of the kind below should suit for conditional formatting:

Resources