So I have a formula that shows if a cell contains text from a list:
=SUMPRODUCT(--ISNUMBER(SEARCH("List of companies in Worksheet A",A1)))>0
It works correct, but I need to further expand this formula.
I have a two data worksheet:
W1 is a list of companies and that show preferred companies for given product in given country,
W2 is a list of documents that show which company has been use in which country for which product.
I need formula that shows if for given document the company is preferred for given country and product.
Above formula solved the issue of company as it checks if company mentioned in W2 appears in W1, now I would need to add two more conditions, to check the country and product.
Current formula is this:
=IF(AND(SUMPRODUCT(--ISNUMBER(SEARCH("List of companies in Worksheet A",A1)))>0,"Preferred", "Non Preferred")
How do I reverse the formula so it will show me in WHICH cell the found value in W1 is so I can use simple VLOOKUP and = formula and and the conditions, like:
=IF(AND(SUMPRODUCT(--ISNUMBER(SEARCH("List of companies in Worksheet A",A1)))>0,B1=Vlookup(SUMPRODUCT(--ISNUMBER(SEARCH("List of companies in Worksheet A",A1))>0,Table in W1,1,"Preferred", "Non Preferred")
I am really stuck, please help.
An example of worksheet A
Company Name
Company Code
Country
abd
12355
Germany
aaa
23322
Austria
asc
432
France
asc
123
USA
asce
1234
Poland
An Example of worksheet B
Company Name
Country
abd - 111
Germany
aaa - 234
Austria
asc - 432
France
asc - 123
UK
asce - 1234
Romania
If I use:
=SUMPRODUCT(--ISNUMBER(SEARCH("List of companies in Worksheet A",A1)))>0
It will highlight 3 bottom rows, however I need to apply second condition so it will highlight ONLY 3rd row, the one with France.
Highlighting is pretty hard because CF rules don't allow to use references to other worksheets besides current one neither array formulas. But you may use a helper column to get the output you need and then hightlight based on that output:
Worksheet A
Worksheet B
Notice France is the only highlighted value because is the only country that fits pattern Company Name - Company&CodeCountry
Formula in column C (array formula, so you must introduce it pressing CTRL+ENTER+SHIFT:
={ISNUMBER(MATCH(A2&B2;'Worksheet A'!$A$2:$A$6&" - "&'Worksheet A'!$B$2:$B$6&'Worksheet A'!$C$2:$C$6;0))}
CR rule to highlight applied to column B is based on this formula:
=C2=TRUE()
UPDATE: If you really really need to skip the helper column, you may benefit from function INDIRECT:
INDIRECT
function
But if your dataset is big, I don't recommend this solution because it may really overcharge your file because INDIRECT is a volatile function:
INDIRECT – Excel’s Most Evil
Function
Besides, if your dataset is fixed (I mean it goes always in the same Address like A2:C6 or A2:A1000, whatever but always the same) you may use it, but it it changes all the time, it will slow down your file.
Anyways, you can make a CF rule based on this formula:
=ISNUMBER(MATCH(A2&B2;INDIRECT("'Worksheet A'!$A$2:$A$6")&" - "&INDIRECT("'Worksheet A'!$B$2:$B$6")&INDIRECT("'Worksheet A'!$C$2:$C$6");0))
Related
I have a huge list of different car names which are repeating and their types. I need to sum the amout of types each car has. For example Name1 has 2 van and one medium, Name2 has 2 van 1 medium, Name3 has 1 non_cargo and 2 medium and so on.
I don't know how to make a formula for that.
I have uploaded example screenshot.
Thank you in advance.
Without no excel version constraint you can use the following assuming your names are in the range A2:A10 for example:
=HSTACK(UNIQUE(A2:A10), COUNTIF(A2:A10,UNIQUE(A2:A10)))
It returns in the first column the unique names and the second column the corresponding counts for each unique names.
If you want to have a count by name and type better to use a Pivot Table like this:
When using Office 365 you could use:
=LET(data,A1:B12,
_d1,INDEX(data,,1),
_d2,INDEX(data,,2),
u,UNIQUE(data),
_u1,INDEX(u,,1),
_u2,INDEX(u,,2),
m,MMULT(
(TRANSPOSE(_d1)=_u1)*
(TRANSPOSE(_d2)=_u2),
SEQUENCE(COUNTA(_d1),,1,0)
),
HSTACK(u,m))
In older Excel you can use the following:
In D2 use: =IFERROR(INDEX(A$1:A$12,MATCH(0,COUNTIFS($D$1:$D1,$A$1:$A$12,$E$1:$E1,$B$1:$B$12),0)),"") drag from D2 to E12 (or up to when you see empty values).
In F2 use =COUNTIFS($A$1:$A$12,$D2,$B$1:$B$12,$E2) and drag down.
IFERROR(INDEX($I$7:$I,MODE(IF($I$7:$I<>"",MATCH($I$7:$I,$I$7:$I,0)))),"No data")
With this formula, which calculates the most common text value, I need to have the 2nd most common.
Column I content:
Apple
Orange
Apple
Apple
Orange
In this example, I need to get Orange. How is that possible? I can't figure how.
A PivotTable might suit:
and copes with ties for rank.
You can extract the most frequent item in the list with an array formula.
=INDEX(MyList,MATCH(MAX(COUNTIF(MyList,MyList)),COUNTIF(MyList,MyList),0))
Note that an array formula must be confirmed with Shift+Ctl+Enter instead of the customary singular Enter required for normal formulas. When entered wrongly it will display a #NUM! error.
For simplicity's sake I have used a named range MyList in the formula. However, if you prefer, you can replace the name with something like $I$7:$I$1000.
To extract the second-most frequent expression in the list you could use a formula constructed analogue to the above.
=INDEX(MyList,MATCH(LARGE(COUNTIF(MyList,MyList),MAX(COUNTIF(MyList,MyList))+1),COUNTIF(MyList,MyList),0))
This formula is built on the logic that n equals the highest number of occurrences. Therefore the second highest must rank as n + 1, being MAX(COUNTIF(MyList,MyList))+1) in the above formula. By the same method the third ranked could be extracted.
You can embed these formulas in an IFERROR() function.
I found this on Mr Excel
Return most common, 2nd most common, 3rd most common, etc. text string in an array
Spreadsheet Formulas
Cell ___ Formula 'Notice that the cells are B2, D2, E2. Column C is blank
B2 =IF(A2="","",IF(COUNTIF(A$2:A2,A2)=COUNTIF($A$2:$A$100,A2),COUNTIF($A$2:$A$100,A2)+(ROW()/1000),""))
D2 =IF(ROWS($1:1)>COUNT(B:B),"",INDEX(A:A,MATCH(LARGE(B:B,ROWS($1:1)),B:B,0)))
E2 =IF(D2="","",COUNTIF($A$2:$A$100,D2))<br><br>
Results
___ A ________ B ___C ___D _________E
1 Data Set:___Helper ____ Name ____ Occurrences
2 Harmon _____________ Williams ______4
3 Smith _______________ Smith ________3
4 Smith _______________ Harmon ______2
5 Harmon_____ 2.005
6 Williams
7 Williams
8 Smith _______3.008
9 Williams
10 Williams ____4.010
you can try to tie this all together in a single formula but it's simpler and more agile in a spreadsheet environment to just break out the problem in a few separate steps.
take a given column of values you're wanting to count/rank - i'll call it RankList in examples below.
if you're not setting named ranges (do yourself a favor and use named ranges) you'll want this to be your column range - i.e. A:A
now in another column use
=unique(RankList)
there's your list of unique values, now we just need to count the instances of each unique value in the original RankList - this is simple - in the next column over simply use
=countif(RankList,B1)
B1 above represents the cell adjacent to the formula, wherever that might be on your sheet. now autofill the formula in with the relative cell value for each item. now all of your items are counted by instance.
now we want to sort them by value, highest to lowest. create another named range, selecting the two columns containing the =unique(RankList) and =countif(RankList,B1) formulas that were just created, i'll refer to it as UniqueCount
use the following
=sort(UniqueCount, 2, false)
that's it. again you can accomplish this by stacking formulas like in the above examples, but in practice i've found that you won't know what you'll want to do additionally with your data/sheet later on. keeping it broken up in discrete steps like this makes it much easier to make adjustments.
Update Below -- 6/4
I have two worksheets in excel. One is a list of donors with their check#/amount/ Donor ID ( "donations" worksheet) and the other is a copy of the accounting info with Donor ID/check#/amounts (quickbooks worksheet). Quickbooks does not have the DonorID's filled in yet.
The issue I have is that i need match up Donor ID's with their checks. To get this i need to match the check# and amount in "Quickbooks" to the same in "Donations", when they match, it will give me the Donor ID that corresponds with that check.
Here is how it is laid out:
Donations Worksheet:
A B C
DonationID Check# Amount
1 179 106 $200
2 210 106 $500
3 220 106 $600
Quickbooks Worksheet:
A B C
DonationID Check# Amount
1 n/a 106 200
2 N/a 1074 500
3 N/a 300 1000
When I ask to find "check# 106 is for $200" it should tell me that it is from Donor 179.
Some checks don't match and are not from donors. The list has close to 50000 names.
Please ask me any questions so i can clarify this more. I am also somewhat new to all this and apologize if I am not to clear.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Thanks everyone for your help. We are not there yet but you were all steering me in the right direction.
I have added a screen shot of the page for reference because the team was having issues making the given formula's work. I also combined the two sheets onto one page so there is less cross worksheet referencing and will be easier to read.
Cknum = Check#
Two column matches typically come in one of two typical configurations; one being an array formula and the other being a standard formula. Both use variations of an INDEX/MATCH function pair.
The standard formula for Quickbooks!A2 would be,
=IFERROR(INDEX(Donations!A$1:A$999, MIN(INDEX(ROW($1:$999)+((Donations!B$1:B$999<>B2)+(Donations!C$1:C$999<>C2))*1E+99, , ))), "No match")
The array formula version for Quickbooks!A2 would be,
=IFERROR(INDEX(Donations!A$1:A$999, MATCH(1, (Donations!B$1:B$999=B2)*(Donations!C$1:C$999=C2), 0)), "no match")
Array formulas need to be finalized with Ctrl+Shift+Enter↵ rather than simply Enter↵.
Once one of the formulas has been put in Quickbooks!A2 correctly, fill down as necessary to catch the values from other rows. Note that I have changed the third line of your sample data to demonstrate a second DonationID lookup for Check# 106.
With ~50K records, there is the distinct possibility that multiple matches could be made on both columns B and C. To capture the subsequent second, third, etc matches from the Donations worksheet, change the MIN function to a SMALL function and use a progressive COUNTIFS function to adjust the k ordinal.
=IFERROR(INDEX(Donations!A$1:A$50000, SMALL(INDEX(ROW($1:$50000)+((Donations!B$1:B$50000<>B2)+(Donations!C$1:C$50000<>C2))*1E+99, , ), COUNTIFS(B$2:B2, B2, C$2:C2, C2))), "No match")
After setting up some intentional duplicates in the Donations worksheet like this,
DonationID Check# Amount
179 106 $200
210 106 $500
220 106 $600
979 106 $200
910 106 $500
920 106 $600
You should receive results like the following.
The IFERROR function has been used to catch non-matches and show no match rather than the #N/A error.
I have modified the values in your single worksheet sample data to show a variety of matches as well as one case where the chknum and amount were duplicated by two different donationID entries.
The matching records are color-coded for quick reference. I've made this sample workbook publically available at my Docs.com-Preview site.
VLOOKUP_w_Multiple_Criteria_and_Duplicates.xlsx
There is an existing command, DGET, that can be used for multiple criteria.
In your QB worksheet, I added another few rows, starting at A7.
ID CheckNo Amount
106 200
The ID is 179
Note that I changed Check# to CheckNo. I also added a definition of donationDB, from A1 to D4.
The DGet statement is where the 179 is. I used =DGET(donationDB,Donations!B1,Quickbooks!A7:C8)
What the DGET does is to look up the database, tell it you're looking for the Donor ID in B1, using the criteria in the fields A7 to C8.
One quick way out of this problem is to create a Pivot Table on the Donations data and then use GETPIVOTDATA to pull values out of it to get the donation id on the Quickbooks table.
This is easily done if the donation ID is always numeric. You set up a Pivot Table with row fields including check number and amount. You then set the values to be equal to MIN or MAX of the donation ID. If there is only one result you will get it immediately. If there is a clash, you can determine this by switching over to COUNT and flag any of those >1.
Once you have the table set up with MAX you can then quickly use GETPIVOTDATA to pull in the matching value.
This assumes that your amount values are close enough (in the floating point decimal sense) to match. Nearly all will be. Some may not. If you can get 50k records down to 100 though to double check, then life is good.
Picture of sample data and Pivot set up, shows the Pivot Table built on the left data (with the donation ID). The lookup data is on the right.
Formula for the lookup is a simple GETPIVOTDATA, this is in cell F3 and copied down.
=GETPIVOTDATA("Donation",$B$10,"Check",G3,"Amount",H3)
You will get the #REF! error if a match is not made. See the last row for an example.
To compare two sets of data by matching several fields and obtain another field as a result of the match, I suggest to add a new field to each database to create a concatenated value of the Fields to match, then use a VLOOKUP and COUNTIF formulas combined.
Let’s use the sample data provided by Jeeped, in which we have:
Data A: Quickbooks - range D1:M24 and Data B: Donations – range R1:W23, to be extended to C1:M24 and Q1:W23 respectively
Add Field “Key” to concatenate the Fields to match (2 fields in this case, but also works for more), use | as separator.
Data A: Add Field “Key” in Column C and enter this formula
=CONCATENATE($E2,"|",$M2)
Data B: Add Field “Key” in Column Q and enter this formula
=CONCATENATE($V2,"|",$W2)
Enter formulas to match concatenated fields and retrieve required information (also indicates items duplicated)
Data A: Add this formula in column N
=IF(COUNTIF($Q$1:$Q$23,$C2)>1,
"Duplicated: "&COUNTIF($Q$1:$Q$23,$C2),
IFERROR(VLOOKUP($C2,$Q$1:$W$23,2,0),""))
Data B: Add this formula in column X
=IF(COUNTIF($C$1:$M$24,$Q5)>1,
"Duplicated: "&COUNTIF($C$1:$M$24,$Q5),
IFERROR(VLOOKUP($Q5,$C$1:$M$24,2,0),""))
I use the AVERAGEIFS function for getting a numeric value based on multiple criteria. If you are not confident that the criteria would only return one value, then you can wrap in a COUNTIFS statement.
=IF(COUNTIFS($A$1:$A$10, crit1, $B$1:$B$10, crit2) = 1, AVERAGEIFS($C$1:C$10, $A$1:$A$10, crit1, $B$1:$B$10, crit2), #N/A)
This only works for numeric values though.
I have an issue. I have 2 large tables of student payments that I need to "reconcile" with each other.
In Table 1, I have students full name, formatted "Smith, John ". I'm using a formula to just return the last name formatted "SMITH".
In Table 2, the students name is at the end of a long string of text which typically looks like this:
VAED TREAS 310 DES:XXVA CH33 ID:xxxxxxxxxxxxxxx, INDN:COLLEGE I WORK FOR CO ID:xxxxxxxxxx CCD, PMT INFO:REF48CH33 TF VA FILE NO xxxxxxxxx *TE, RM xxxxxx-xxxxxx JOHN A SMITH -
Whenever I try to use vlookup for "SMITH", and reference the cell in the second table, I consistently get an #N/A error.
I've uploaded a specific example of what I'm doing here.
You need to create a column within the same table that returns SMITH. In the workbook you uploaded, your VLOOKUP formula was referencing a load of blank cells so it couldn't find SMITH in the left-hand most column.
I made a couple of changes and re-uploaded the workbook for you here:
http://we.tl/WjDiLtHDnm
Table 1 now has the surname added to the very final column. I adjusted your vlookup formula to now use the index and match functions to do what you were intending. The only reason I didn't use Vlookup is that I put the surname on the far right (Vlookup only works referencing from the left hand most column and returning values in columns to the right).
B
In worksheet 'A' I have row 1 for college names. College ID is
concatenated with the college name, after a space, within parentheses.
Sheet 1 (A1:E1):
"Wyndall college (123)", "Jeffersone college (99)", "Lyndale College (45)", "Lincoln college (60)", "Salt Lake College (40)"
In worksheet 'B', I have column A for college names (no college ID
concatenated) and column B for number of students. Sheet 2 (A1:A4):
"wyndall college" 100
"Gates College" 300
"Jefferson College" 50
"Lincoln college" 150
Worksheet B many not have all college names that exist in worksheet
A and vice versa!
I want to populate row 2 (A2:E2) in worksheet A with the number of students
from worksheet 'B' if the college name matches (even partial) in the
two worksheets.
How do I do that thru Excel formula and functions?
For example:
After parsing with Text To Columns. On a larger scale Fuzzy Lookup might be more suitable.
I don't know what you mean by a "partial match". If you can match up to the ID number, and the ID number is always inside parentheses, then you can use something like:
B1: =IFERROR(VLOOKUP(TRIM(LEFT(A1,FIND("(",A1)-1)),B!$A$1:$B$4,2,FALSE),"")
and fill down.
If you only want to match the first word, then look for the first space in the Find function. If you mean something else by a "partial match", you'll have to add detail.