Excel, IF and COUNT duplicates - excel

So here it is,
Column A has duplicate and unique number values, Column B has duplicate and unique Strings (Names). I need to count the instances of unique number values in A matched to their name in B.
So it would be like =COUNTIF(B1:B100,"XYZ") "Then counts all unique number values in A1:A100 that "match" or have XYZ in column B.
Col A - Col B
ABC - 963
ABC - 963
FFF - 367
FFF - 367
FFF - 234
XYZ - 678
XYZ - 221
XYZ - 334
What I need:
ABC = 1 ( one unique instance where Col A and Col B (ABC,963) )
XYZ = 3 ( three unique instances (XYZ,678 : XYZ,221 : XYZ,334
FFF = 2 ( two unique instances ( FFF,367 and FFF, 234 )
So I need to sum up all the unique instances of Column A that only match the strings in column B.
Thanks in advance !, I'll keep searching in the meantime !

I believe that you are looking to retrieve a count of the unique combinations of number and name. Perhaps something like the following.
        
The formula in E2 is,
=SUMPRODUCT((A$2:A$99<>"")/COUNTIFS(B$2:B$99, B$2:B$99&"", A$2:A$99, A$2:A$99&""))
The formula in E4 is,
=SUMPRODUCT((A$2:A$99=D4)/COUNTIFS(B$2:B$99, B$2:B$99&"", A$2:A$99, A$2:A$99&""))
Fill E4 down as necessary.

Related

Compare two columns and get the values from another column?

I have an excel table with multiple columns, I need to add value for every transaction_id, how can i compare column C with column J and enter values from K into D column?
Table looks like this:
C
D
J
K
transaction_id
amount
transaction_id
amount
1
5
1000
2
1
1000
5
118
200
118
117
500
I need to match the exact transaction_id and move from the right to left amount value if transaction id is the same, how can I do that?
Just use VLOOKUP:
Formula in D is:
=VLOOKUP(C2,$J$2:$K$5,2,FALSE)

adding another column in excel being compared to another

I have 2 spreadsheets in excel. Spreadsheet 1 contains many columns including ssn and employee ID. Spreadsheet 2 contains different columns and has an ssn column but not the employee id. I wanted create a new column in Spreadsheet 2 that is called employee id and match it with the employee's ssn that it is correlated to in Spreadsheet 1. I feel like I would need to use VLOOKUP but I am not entirely sure. Any help ? Thanks
=VLOOKUP(L2, [spreadhseet1.xlsx]spreadhseet1!$A:$P, 2, FALSE)
Above is the formula that I used. L2 is the column in table2 that contains the employee's ssn. I then took the range of all values in table1 from column A-P. Column 2 in spreadhseet2 contains the employee id which is why I entered 2. Not sure why it is providing an error
VLOOKUP is the correct function.
If you have a source similar to
[A] [B]
1] SSN | empid
---------------------
2] 123 | ABC
3] 456 | DEF
....
99999] 987 | QQQ
^------- index = 2 for return value
^------------------ lookup is in first column
and want to populate destination with "empid":
[a] [b] [c]
1] ssn | empid | col2 | col 3 | ..
---------------------------------------------
2] 123 | | B | C |
3] 456 | | d | e |
^----- formula here
^------------- this value is used as lookup
Then you place in the empty "empid" column a formula
=VLOOKUP(A2, 'Sheetname'!$A2:$B9999 , 2 , false)
where
A2 is your source column. 2 obviously same row.
'Sheetname'!$A2:$B99999 is your data source area, excluding header.
2 is your 1-indexed column to return
False is to return a precise match
Notice that you may be need to handle a case where lookup value does not exist in source data. This will return #N/A and can be handled simply
If you absolutely NEED to do this across files, it's possible, but you risk breaking something if the files are not there. It's explained here.
NOTICE If you are on a non-US version of Excel, functions may separate with ";" and have different names

Excel or VBA - VLOOKUP with IF Coniditon

Hi,
I would like to investigate a huge list that I can distinguish the Acc numbers according to the mail adresses. The things that I
would like to do if email adresses has a seperate Acc and if they
equal each other( I mean if Acc numbers are equal),write a "equal" if
the criterias were not equal with the same email then write a
"multiple criteria"..
Is there any way to do that with Excel formulas or VBA ?
Mail Acc
uralsmh#gmail.com C1234
uralsmh#gmail.com C2345
Part 1 - check for duplicates
Create a helper column that sticks columns A and B together and then count this column. You can use the & character for this:
A B C D
1 abc 123 =A1&B1 =COUNTIF($C$1:$C$1000,C1)
2 abc 123 =A2&C2 =COUNTIF($C$1:$C$1000,C2)
3 def 123 =A3&C3 =COUNTIF($C$1:$C$1000,C3)
If you get a number greater than 1 in column D, then that row is a duplicate of another row.
Part 2 - find multiple accounts
Now you have found the exact duplicates, any email addresses that match must have different account numbers. So, in column E, just count column A:
A B C D E
1 abc 123 =A1&B1 =COUNTIF($C$1:$C$1000,C1) =COUNTIF($A$1:$A$1000,A1)
2 abc 123 =A2&C2 =COUNTIF($C$1:$C$1000,C2) =COUNTIF($A$1:$A$1000,A2)
3 def 123 =A3&C3 =COUNTIF($C$1:$C$1000,C3) =COUNTIF($A$1:$A$1000,A3)
If you get a number greater than 1 in column E and you had a 1 in column D, you have found an email address with multiple accounts.

CountifS + multiple criteria + distinct count

I'm looking for a formula calculating : distinct Count + multiple criteria
Countifs() does it but do not includes distinct count...
Here is an example.
I have a table on which I want to count the number of distinct items (column item) satisfying multiple conditions one column A and B : A>2 and B<5.
Image description here
Line Item ColA ColB
1 QQQ 3 4
2 QQQ 3 3
3 QQQ 5 4
4 TTT 4 4
5 TTT 2 3
6 TTT 0 1
7 XXX 1 2
8 XXX 5 3
9 zzz 1 9
Countifs works this way : COUNTIFS([ColumnA], criteria A, [ColumnB], criteria B)
COUNTIFS([ColumnA], > 2 , [ColumnB], < 5)
Returns : lines 1,2,4,5,8 => Count = 5
How can I add a distinct count function based on the Item Column ? :
lines 1,2 are on a unique item QQQ
lines 4,5 are on a unique item TTT
Line 8 is on a unique item XXX
Returns Count = 3
How can I count 3 ?!
Thanks
You can download the excel file # Excel file
Newer versions of Excel allow for this problem to be solved in a (relatively) more simple way. It certainly is easier to follow and understand, conceptually.
First, filter the table based on multiple criteria (join multiple with the *):
=FILTER(Table,(Table[Column A]>2)*(Table[Column B]<5))
Then, grab the "Item" column with INDEX:
=INDEX(FILTER(Table,(Table[Column A]>2)*(Table[Column B]<5)),,2)
Next, filter for unique entries:
=UNIQUE(INDEX(FILTER(Table,(Table[Column A]>2)*(Table[Column B]<5)),,2))
Finally, perform a count:
=COUNTA(UNIQUE(INDEX(FILTER(Table,(Table[Column A]>2)*(Table[Column B]<5)),,2)))
Ugly formula, but it works.
=SUM(((FREQUENCY(IF(C2:C10>2,1,0)*IF(D2:D10<5,1,0)*(COUNTIF(B2:B10,">"&B2:B10)+1),ROW(B2:B10)-ROW(B2)))*(ROW(B2:B11)-ROW(B2))>0)*1)
I'll start with the criteria IFS:
IF(C2:C10>2,1,0)*IF(D2:D10<5,1,0)
Gives an array of 1s and 0s for the rows that satisfy both criteria. ARRAY = {1;1;1;1;0;0;0;1;0} for your example.
Where B2:B10 is the Item column, the countif formula:
COUNTIF(B2:B10,">"&B2:B10)
returns {6;6;6;3;3;3;1;1;0} where the number equals the number of item values in B2:B10 alphabetically less than the tested item value.
QQQ goes to 6 [3"TTT", 2"XXX", 1"zzz"]
TTT goes to 3 [2"XXX", 1"zzz"]
XXX goes to 1 [1"zzz"]
zzz goes to 0 [0 less than "zzz"]
Need to add 1 to this array to make sure there are no 0 values:
{7;7;7;4;4;4;2;2;1}.
So when multiplying the criteria, and the countif statement:
(IF(C2:C10>2,1,0)*IF(D2:D10<5,1,0)*(COUNTIF(B2:B10,">"&B2:B10)+1)
You get ARRAY = {7;7;7;4;0;0;0;2;0}.
FREQUENCY(ARRAY,ROW(B2:B10)-ROW(B2))
ROW(B2:B10)-ROW(B2) sets the frequency bins to {0;1;2;3;4;5;6;7;8}. So the output of the frequency formula is {4;0;1;0;1;0;0;3;0;0} where the last 0 is for all values greater than 8.
((ROW(B2:B11)-ROW(B2)>0)*1) equals {0;1;1;1;1;1;1;1;1;1}. Multiplying ARRAY by this removes the 0 count at the start: ARRAY = {0;0;1;0;1;0;0;3;0;0}. [NOTE: B11 is lowest item column cell+1 because of the added array value from the frequency formula for values over 8]
(ARRAY)>0)*1 = {0;0;1;0;1;0;0;1;0;0}
SUM this = 3.
ctrl + shift + enter, because it's an array formula.
cmd + shift + enter for mac.
You could try this:
=SUMPRODUCT(1/COUNTIF(B2:B10,B2:B10))
Credit where credit due, however ... I found it over here:
https://exceljet.net/formula/count-unique-values-in-a-range-with-countif

Vlookup doesn't work with column of string

I have 4 columns, containing 2 columns of names and 2 columns of values, as below. I need to update Column B with value in K, if the name1 = name2. Both name columns are formatted as text, and values columns are formatted as numeric.
(A) Name1 (B) Value1 (J) Name2 (K) Value2
A A 123
B B 456
C X 000
D Y 000
E Z 000
F C 789
I insterted the following vlookup in the first row of column B, but it returns the name in column A.
=VLOOKUP(A4,J2:J22890,K2:K22890)
I'm expecting to have the following result:
(A) Name1 (B) Value1 (J) Name2 (K) Value2
A 123 A 123
B 456 X 000
C 789 B 456
D Y 000
E Z 000
F C 789
Am I using vlookup a the wrong way? or is it due to the fact that I'm looking up strings??
I think it should be
=VLOOKUP(A4,J2:K22890,2,0)
1.First parameter is the value you are looking for,
2.second one is the range (it can be multiple columns, with the referenced data in the most-left column of the selection),
3.followed by the column's number where the records should be retrieved from,
4.and lastly a flag (1 or 0) if you would like to accept similar results (1) or exact matches only (0)
Since I can't edit the post because it's not enough characters and I can't comment because I don't have enough rep...
=VLOOKUP(A4,$J$2:$K$22890,2,0)
This is Alex's post with absolute references for the lookup table array.

Resources