Excel Count matches between 3 criteria - excel-formula

I have 2 columns of data (Names = DataA & DataB).
I have 2 variable sets of codes for which I want to count matches (Names = DataC & DataD).
DataA (Col A)
a
b
b
c
e
.....8000 records
DataB (Col B)
John
Fred
Gerry
Alice
etc.... 8000 records
DataA Variables to match a c ..... (up to 20 - RangeName=DataC)
DataB Variables to match John Fred ... (up to 20 - RangeName=DataD)
I can count the number of matches DataA to DataC using:
SUMPRODUCT((DataA=DataC)*1)
But of I try to add the DataB to DataD criteria it doesn't work
I can do it using multiple Countifs, one for each variable in turn but with larger numbers of variables it gets very messy (example with 4 variables):
COUNTIFS(DataA,$U$72,dataB,AA71)+COUNTIFS(DataA,$V$72,dataB,AA71)+COUNTIFS(DataA,$W$72,dataB,AA71)+COUNTIFS(DataA,$X$72,dataB,AA71)
I don't want to use Pivot Tables and would like a more elegant solution - driving me nuts for 2 days now - hope it doesn't do the same for you!

I may have misunderstood what you are trying to do but using a two criteria SUMPRODUCT works for me.
=SUMPRODUCT(--(DataA=DataC),--(DataB=DataD))
Note that rather than using *1 in the formula to have it calculate calculate the logical functions you should try to use -- in the SUMPRODUCT function.

Related

List result of lookup A in B, B in C without helper column

I have 2 tables:
Table1 containing Customer & Part#
Table2 containing Part# & Type
(The actual data lists are larger)
Table1 (Customer & Part#) & Table3 (Helper):
Customer
Part#
Helper
A
1
X
B
2
Y
C
3
X
A
4
Y
A
5
X
A
5
X
A
2
Y
Table2:
Part#
Type
1
X
2
Y
3
X
4
Y
5
X
Desired result for combination of customer A and Type X:
Part#
1
5
5
These being the 3 results of part numbers in Table1 that are Customer A and the lookup of the Part# results in Type X (see also Helper column).
I'm able to retrieve the results by creating the helper column as shown in the example data, however I want to skip this column and solve it in one go. But I don't know if that's even possible.
I was thinking about something in this direction.. =INDEX (Table1[Part'#],IF(Table1[Customer]="A",ROW(Table1[Customer]))
..but there I get stuck. I think I can pickup from there with IF, ISNUMBER, SEARCH but my head errors there.
Does anybody know a way to skip the helper column for this?
PS I have office365, but FILTER is not yet released by company rules (unfortunately).
PS I prefer a formula solution, but VBA is allowed when necessary
Here is a formula solution for Excel version 2010 to 2019
In I3, formula copied down :
=IFERROR(INDEX(B:B,AGGREGATE(15,6,ROW(A$3:A$9)/(VLOOKUP(N(IF({1},B$3:B$9)),D$3:E$7,2,0)=H$3)/(A$3:A$10=G$3),ROW(A1))),"")

Count occurrences of strings just once per row in Google Sheets

I have strings of spreadsheet data that need counting by 'type' but not instance.
A B C D
1 Lin 1 2 1
2 Tom 1 4 2
3 Sue 3 1 4
The correct sum of students assigned to teacher 1 is 3, not 4. That teacher 1 meets Lin in lessons B and D is irrelevant to the count.
I borrowed a formula which works in Excel but not in Google Sheets where I and others need to keep and manipulate the data.
F5=SUMPRODUCT(SIGN(COUNTIF(OFFSET(B$2:D$2, ROW($2:$4)-1, 0), E5)))
A B C D E
2 Lin 1 2 1
3 Tom 1 4 2
4 Sue 3 1 4
5 1 [exact string being searched for, ie a teacher name]
I don't know what is not being understood by Google Sheets in that formula. Does anyone know the correct expression to use, or a more efficient way to get the accurate count I need, without duplicates within rows inflating the count?
So this is the mmult way, which works by finding the row totals of students assigned to teacher 1 etc., then seeing how many of the totals are greater than 0.
=ArrayFormula(sum(--(mmult(n(B2:D4=E5),transpose(column(B2:D4)))>0)))
or
=ArrayFormula(sum(sign(mmult(n(B2:D4=E5),transpose(column(B2:D4))))))
Also works in Excel if entered as an array formula without the ArrayFormula wrapper.
A specific Google Sheets one can be quite short
=ArrayFormula(COUNTUNIQUE((B2:D4=E5)*row(B2:D4)))-1
counting the unique rows containing a match.
Note - I am subtracting 1 in the last formula above because I am assuming there is at least one zero (non-match) which should be ignored. This would fail in the extreme case where all students in all classes are assigned to the same teacher so you have a matrix (e.g.) of all 1's. This would be more theoretically correct:
=ArrayFormula(COUNTUNIQUE(if(B2:D4=E5,row(B2:D4),"")))

Matlab - filter out identical cell entries

My matrix is a 10000 x 2 one. Looks like this:
Ann Beth
Bob Pete
Sam Sam
Jen Ted
...
There are many lines with identical names in both columns (like Sam). I need just rows with different names. I thought of a for-loop with ismember/string compare but this is very slow and there are some matrixes like this.
Other option that is also slow is to unique the first column and run a for loop with find the unique values and delete every time the values of find are identical. However this is slow as well. Please help to optimize.
Thanks
You can use strcmp to get a logical array of indices corresponding to identical rows, i.e. compare 1st column with 2nd and remove rows corresponding to indices of 1.
Example:
C = {'Ann' 'Beth';
'Bob' 'Pete';
'Sam' 'Sam';
'Jen' 'Ted'};
idx = strcmp(C(:,1),C(:,2))
Here idx looks like this:
idx =
0
0
1
0
Hence the 3rd row contains identical names. Now remove those:
C(idx,:) = [];
C =
'Ann' 'Beth'
'Bob' 'Pete'
'Jen' 'Ted'

agregate in vertical 2 or more colums in EXCEL

I'm looking for a way to take these columns (Name/value)..
Name Value Name Value
a 1 c 3
b 2 d 4
and join them together as follows:
Name Value
a 1
b 2
c 3
d 4
Thanks
A PivotTable constructed with multiple consolidation ranges (one for each pair) would achieve the result you want (but might be little easier that copy and paste):

Excel sort data in newspaper style columns

I have an excel sheet that has names and extension numbers. The sheet is designed to be printed as a reference and so it has the data split into 3 columns like how a newspaper is laid out.
EXT Name EXT Name EXT Name
1 bob 4 pete 8 sam
2 dave 5 sally 9 john
I need to have excel sort this data on name, A-Z. I can only work out how to make it sort one column at a time and so I end up having to manaually sort the data every time I add or remove information.
Can excel sort all 3 columns top to bottom and left to right?
Thanks!
Maybe this KB artikel helps.
Or u can try using the small function like
Column A
=SMALL($A$1:$A$9;0+ROWS(A$1:A1))
Column C
=SMALL($A$1:$A$9;30+ROWS(A$1:A1))
In this case you clone the sorted dataset, which is in two columns
The value for the B colums can be found using a vlookup. the value 0 and zero are an offset, so the length of the page is fixed

Resources