count with multiple crieria - excel

I am stuck with a problem. Lets say I have the following data in range A1:K4
row1 1 2 3 4 5 6 7 8 9 10
row2 2 3 4 5 6 7 8 9 10 11
row3 3 4 5 6 7 8 9 10 11 12
row4 3 5 6 7 8 9 10 11 12 13
And the following data in range N1:P4
1 2 3
2 3 4
3 4 5
11 12 13
I want formulas in range R1:R4
The desired output should be R1=1, R2=2, R3=3, R4=1
i am trying to evaluate first set of numbers 1 2 and 3 and check in every row from row1 to row4 and find out how many rows matched all 3 numbers and the put the value in cell R1.. continue this for all 4 sets of number. Can someone help me with a formula?
Thanks

You could use this formula in R1 copied down to R4
=SUMPRODUCT((MMULT(COUNTIF(OFFSET(B$1:K$4,ROW(B$1:K$4)-ROW(B$1),0,1),N1:P1),{1;1;1})=3)+0)
although I've cheated a bit, there, because {1;1;1} is variable based on the number of columns in N1:P1 (and so is the 3), so for a more generic version (which would allow N1:P1 to be any size row) you can use this "array formula"
=SUM((MMULT(COUNTIF(OFFSET(B$1:K$4,ROW(B$1:K$4)-ROW(B$1),0,1),N1:P1),TRANSPOSE(COLUMN(N1:P1)^0))=COLUMNS(N1:P1))+0)
confirmed with CTRL+SHIFT+ENTER

Related

Deleting a row with VBA in Excel gives invalid reference in another table

I have an Excel Workbook with 2 sheets. Each sheet contains a formatted table.
The tables start at row2 and feature an internal numbering in columnA achieved by the formulas
=Row()-Row(talble1)+1 and =Row()-Row(talble2)+1
sheet2:
In table2/columnB I concatenate 2 of the internal row indices from table1 using the formulas
table2/internal row1: =CONCATENATE(sheet1!A2;";";sheet1!A3;";")
table2/internal row2: =CONCATENATE(sheet1!A4;";";sheet1!A5;";")
table2/internal row3: =CONCATENATE(sheet1!A6;";";sheet1!A7;";")
table2/internal row4: (...)
It looks like this:
sheet1/table1: sheet2/table2:
A B C A B C
1 1
2 1 2 1 1;2
3 2 3 2 3;4
4 3 4 3 5;6
5 4 5
6 5 6
7 6 7
8 8
9 9
If I "manually" delete the 2 rows with internal indices 3 and 4 in table1, the numbering automatically adjusts. Also, the references in internal row2/columnB of table2 become invalid, which makes total sense. The formula of internal row3 in table2 automatically adjusts to the deletion in table1 and remains valid.
It then looks like this:
sheet1/table1: sheet2/table2:
A B C A B C
1 1
2 1 2 1 1;2
3 2 3 2 invalid
4 3 4 3 3;4
5 4 5 4
6 6 5
7 7 6
8 8
9 9
Now comes the issue:
If I do the deletion described above using a VBA macro, the references in internal row3 of table2 become invalid as well! When I check the formula I see that it still references cells A6 and A7 which don't exist anymore in table1.
I used the code
sheet1.ListObjects("table1").DataBodyRange.Rows(4).Delete Shift:=xlUp
sheet1.ListObjects("table1").DataBodyRange.Rows(3).Delete Shift:=xlUp
It looks like this:
sheet1/table1: sheet2/table2:
A B C A B C
1 1
2 1 2 1 1;2
3 2 3 2 invalid
4 3 4 3 invalid
5 4 5 4
6 6 5
7 7 6
8 8
9 9
What is the explanation for the different behaviour of deleting a row in table1 manually or by VBA code?
I also recorded macros when deleting the rows manually and I could not detect anything that explains why my macro code leads to the invalid references in internal row3 of table2.

Excel: I want to remove duplicate values in same row and many columns

I want to delete duplicate values in same row and multiple column in excel... i want this
A B C D E F G H I J K RESULT
R1 8 0 1 8 1 5 8 1 9 5 5 80159
R2 7 8 7 7 4 5 0 7 6 8 9 78450689
R3 5 2 0 6 4 2 7 6 1 3 0 52064713
R4 4 3 5 0 7 2 5 3 2 4 8 4350728
If one has the Dynamic Array formula:
=CONCAT(UNIQUE(A1:K1,TRUE))
If not then the assumption is that 0 will never be in the first column and that the data is as you provided, one number per cell:
=MMULT(TRANSPOSE(MODE.MULT(IF(MATCH(A1:K1,A1:K1,0)=COLUMN(A1:K1),A1:K1*{1;1}))),TRANSPOSE(10^(COUNT(MODE.MULT(IF(MATCH(A1:K1,A1:K1,0)=COLUMN(A1:K1),A1:K1*{1;1})))-TRANSPOSE(ROW(INDEX($ZZ:$ZZ,1):INDEX($ZZ:$ZZ,COUNT(MODE.MULT(IF(MATCH(A1:K1,A1:K1,0)=COLUMN(A1:K1),A1:K1*{1;1})))))))))
Depending on ones version this may need to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.
If it is text or the numbers are more than one digit then vba will probably be needed.

I would like to change the color of a row if two rows with the same contents in one column differ in value in another column

So I have been working on this for a while now but can't seem to get it.
Essentially if the contents in column C (NAME) match, I need to see if their rows match value in column K (Y/N).
If they differ in Column K, the entirety of both rows should turn yellow.
Additionally, I would like that if they match in column C, and they are both "No" in column K, both rows turn red.
I believe this to be done as a custom rule in conditional formating but this is all I could come up with, unsure how to proceed. (I am operating in Google Sheets since its a shared doc but I can manage with Excel.
=AND($C1<>"",COUNTIF($C:$C,$C1)>1, COUNTIFS($C:$C,$C1,$K:$K,$K1)>0)
Some sample data; here both of Jane's rows should be red and Alex's rows should be yellow:
43425.45184 NA Morg 4 7 5 6 7 6 6 Yes
43423.65523 NA Alee 4 9 8 7 8 8 9 Yes
43425.4461 NA Alee 4 8 8 8 8 8 8 Yes
43420.93822 NA Bale 4 8 7 7 6 10 7 Yes
43424.40326 NA Jane 5 9 8 8 9 9 7 No
43430.45766 NA Jane 5 10 10 10 10 10 10 No
43424.51362 NA Alex 3 8 8 8 4 6 6 Yes
43430.48237 NA Alex 4 6 3 5 2 7 6 No
43428.76583 NA Allison 4 8 8 8 7 6 8 Yes
Think these two will do it.
=AND(COUNTIF($C:$C,$C1)=2,COUNTIFS($C:$C,$C1,$K:$K,"No")=2)
Above is fill red
=AND(COUNTIF($C:$C,$C1)=2,COUNTIFS($C:$C,$C1,$K:$K,"Yes")=1)
Above is fill yellow

SUM function produces a #VALUE! error when using in array formula

I have the following values in a sheet (in A1:G10) range:
1 1 1 1 1 1 1
2 2 2 2 2 2 2
3 3 3 3 3 3 3
4 4 4 4 4 4 4
5 5 5 5 5 5 5
6 6 6 6 6 6 6
7 7 7 7 7 7 7
8 8 8 8 8 8 8
9 9 9 9 9 9 9
10 10 10 10 10 10 10
I need to calculate the sum of differences of values between two rows in the array above when both rows are defined by row numbers, for example: sum of differences of values between 10-th and 1-st rows, between 9-th and 2-nd rows and so on. Row numbers I defined in J1:K10 range:
1 10
2 9
3 8
4 7
5 6
6 5
7 4
8 3
9 2
10 1
Then I selected L1:L10 range, and in the first cell of it I entered the following formula:
=SUM((OFFSET(A1,INDEX(K1:K10,ROW(K1:K10)-ROW(K1)+1)-1,0,1,7)-OFFSET(A1,INDEX(J1:J10,ROW(J1:J10)-ROW(J1)+1)-1,0,1,7)))
and then pressed CTRL+SHIFT+ENTER so the formula is enterd as an array formula. And the formula returned a #VALUE! error for each cell in the range.
I tried to evaluate the formula, and it evaluates correctly except the last step: SUM({9,9,9,9,9,9,9}) becomes a #VALUE!
Here is a screenshot of the sheet for clarity:
What I'm doing wrong? Please suggest.
use SUMPRODUCT in L1:
=SUMPRODUCT(INDEX($A$1:$G$10,J1,0)-INDEX($A$1:$G$10,K1,0))
and copy down.

Excel - How do I create a cumulative sum column within a group?

In Excel, I have an hours log that looks like this:
PersonID Hours JobCode
1 7 1
1 6 2
1 8 3
1 10 1
2 5 3
2 3 5
2 12 2
2 4 1
What I would like to do is create a column with a running total, but only within each PersonID so I want to create this:
PersonID Hours JobCode Total
1 7 1 7
1 6 2 13
1 8 3 21
1 10 1 31
2 5 3 5
2 3 5 8
2 12 2 20
2 4 1 24
Any ideas on how to do that?
In D2 and fill down:
=SUMIF(A$2:A2,A2,B$2:B2)
Assuming that your data starts in cell A1, this formula will accumulate the hours until it finds a change in person ID.
=IF(A2=A1,D1+B2,B2)
Put the formula in cell D2, and copy down for each row of your data.

Resources