Excel - Compare more than a column using VLOOKUP - excel

I need to compare my list of latitude/longitude (columns 4 and 5) with a database containing latitude/longitude data (columns 1 and 2) and its associated data (column 3). This associated data I need to ascribe to the relevant latitude and longitude in column 6. There are no duplicates in the database.
I have tried to use the index functionality etc but have had little luck.
DatabaseLat DatabaseLon Data Lat Lon CopiedData
31.2 -87.9 5 30.5 -87.1 3
31.9 -88.3 6 31.9 -88.4 10
31.9 -88.4 10 54 -87.1
31.1 -87.2 2 31.2 -87.9 5
30.5 -87.1 3

This was something close to what you were looking forward to, by just using formula than a macro/script.
Essentially done using a concatenate function and VLOOKUP.
Step 1. concatenate value from your database and add it under Col A.
Step 2. Use VLOOKUP as in the image and compare using the concatenated value.
=VLOOKUP(CONACTENATE(H2,I2), $A$2:$D$10,4, 0)
Note: the syntax is using LibreOffice the function name may slightly differ.

Most likely you will have to:
Write a VBA Excell macro script link
Make use of for each loop, to go through every cell of column 4 and compare it to the same row of column 1.
If they hold the same value you just check column 2 and 5 simply by adding 1 to the current column number, which will move you to the right. eg.
if cell E5 == A1 then [E +1 = F ] if cell F5 == B1, you have a match. So you can extract from C1 the Database number.
Or, take a look at this methods link
I can't help more, I don't work on windows sorry, and good luck.

Related

Create Comma Separated List In Excel

I have two workbooks that I need to pull data from workbook1, to workbook2. The identifier to achieve such is empID Now for eachempID I need to show what location(s) they worked. So sample data looks like this
Workbook1
empID.....Name....Address...City...State....Zip
1
2
3
4
5
Workbook2
empID.......locationworked
1 12
2 33
1 11
4 22
3 9
1 55
5 19
2 76
1 99
I have used this formula to return the data to a different cell for each empID
=IFERROR(INDEX($B$2:$B$8, SMALL(IF($A$11=$A$2:$A$8, ROW($A$2:$A$8)-ROW($A$2)+1), ROW(1:1))),"" )
But I want to create a Comma Separated list and put everything in one cell, like so
1 11,12,55,99
2 33,76
etc
Is there a way to modify the syntax so that a comma separated list is created like in my desired output?
In workbook 2, I added this formula to column C
=IFERROR(VLOOKUP(A1,A2:$C$50,3,0)&","&B1,B1).
This assumes that your data goes as far down as row 50. Replace $C$50 with whatever row is last in your spreadsheet.
If this is a variable list, use
=INDIRECT("A2:C"&MATCH(TRUE,D:D="",0),1)
in place of the
A2:$C$50
however don't forget to use Ctrl + Shift + Enter to set the formula to an array.
Next, copy this formula down all rows. The VLOOKUP will work up the sheet. Then you can reference this list from your report sheet (I believe in this case its Sheet 1) with a VLOOKUP. it will automatically pick the first instance of each employee ID which contains the csv list.
I'd like to point out that whilst bad_neighbor's solution is quite accurate and reusable for future data changes, it is often preferable to avoid lookups where possible, and to store calculated results as values, since these aren't perfectly efficient and tend to slow down the sheet something awful given a larger quantity of data, for example when filtering / unfiltering. It's worse in older versions.
So, if this list formatting were part of a manual operation, and assuming the requirement is for each list item to be in ascending order (per the question's output), I'd do the following instead:
If workbook2's order is important, add an index of the rows (D1 := 1; D2 := D1 + 1; paste values).
Sort workbook2 by [A ascending, B descending], including index if present.
Apply this formula to column C - a fillup version of the lookup.
C1 := IF(A1=A2,C2&", "&B1,B1)
Copy-paste special values column C.
Lookup from workbook1 + copy-paste special values.
Optionally sort back according to original index (D) in workbook2.

Excel, Sumproduct, multiple conditions search in {}

I run into several postings on the internet (incl. stackowerflow) with code like this
=SUMPRODUCT((A1:A10="Marketing")*(B1:B10={"North","South"})*(C1:C10))
Conditions for search are neatly put into {}. I have 28 such conditions to search for, so I'm looking for a way to make the formula easier to read. If I try it, i get N/A.
Is there a trick I'm missing?
I'm aware that it can be written
(B1:B10="North") + (B1:B10="South")
but with 28 items it is going to be long.
Thank you in advance
EDIT1: (Disregard)
Tried Axel's suggestion
Simple example
- A B C D
1 1 2 3
2 1 2 2 3
3 2 4 4 6
4 3 6 6 9
=SUMPRODUCT((A2:A4={2,3})*(B2:D4))
Returns Sumproduct(({1,2,3}={2,3})*(B2:D4)) -> I still get N/A for last column when you continue in process
Same for
=SUMPRODUCT((A2:A4=A6:B6)*(B2:D4))
where A6:B6 is list of conditions
or
=SUMPRODUCT((A2:A4=testrange)*(B2:D4))
I'm trying to put all conditions within formula {"case1","case2",...} and so but can't make it work.
Edit 2:
Ok, I see the difference now.
Initial formula is column by column by column
What I'm trying to solve
Column A- list of accounts, I need to find 28 of them
Row 1 - months (conditions varies)
Range B2:AA462 - values
I can write it all with (A2:A462="account1")+(A2:A462="acount2")... up to 28 cases, but I'm asking whether there is a way to write it more simpler
Something like initial A2:A462={"North","South"}
Something like
=Sumproduct((A2:A462={"account1","account2",...})*(B1:AA1="June")*(B2:AA462))
Is there a way write this somehow?
EDIT 4:
Few weeks later inspired by Axel's inputs
=SUMPRODUCT(MMULT(--(A2:A7=G1:J1),ROW(1:4)/ROW(1:4))*(B1:E1=G4)*B2:E7)
Can be grown into
{=SUMPRODUCT(MMULT(--(A2:A7=TRANSPOSE(namedrange)),ROW(OFFSET(A1,0,0,COUNTA(namedrange)))/ROW(OFFSET(A1,0,0,COUNTA(namedrange))))*(B1:E1=G4)*(B2:E7))}
Ok, named range, has conditions within column, more natural way to keep a list of conditions you want to filter for. Also MMULT is now flexible, and counts number of conditions and adjust number of rows to multiply by.
Whole formula must be entered as array formula.
{"North","South"} is the array literal for a row vector. That means it is as if "North" and "South" is placed in juxtaposed cells in one row. So if "North" is in E1 and "South" is in F1, then the formula could also be:
=SUMPRODUCT((A1:A13="Marketing")*(B1:B13=E1:F1)*C1:C13)
With more criteria it could be:
=SUMPRODUCT((A1:A13="Marketing")*(B1:B13=E1:H1)*C1:C13)
It is important that the criterias are in a row vector (one row, multiple columns) since the B1:B13 is a column vector.
Answer to your Edit 2:
The approach:
=SUMPRODUCT(((A2:A462="account1")+(A2:A462="account2")+...+(A2:A462="account28"))*(B1:AA1="June")*B2:AA462)
, which will work, is different from (A2:A462={"account1","account2",...,"account28"}). The latter cannot work since it creates a matrix of 461 rows and 28 columns while the working one ((A2:A462="account1")+(A2:A462="account2")+...+(A2:A462="account28")) is only a vector of 461 rows in one column.
The equivalent could be:
=SUMPRODUCT(MMULT(--(A2:A462={"account1","account2",...,"account28"});ROW(1:28)/ROW(1:28))*(B1:AA1="June")*B2:AA462)
and if "account1","account2",...,"account28" are in AC1:BD1 then also:
=SUMPRODUCT(MMULT(--(A2:A462=AC1:BD1);ROW(1:28)/ROW(1:28))*(B1:AA1="June")*B2:AA462)
What is this doing? It uses MMULT to transform the matrix of 461 rows and 28 columns into a vector of 461 rows by multiplying the matrix with a row vector of 28 rows filled with 1.
So if there is a 1 in one of the 28 columns in each row of the matrix, then there will also be a 1 as the row value of the resulting vector of 461 rows.
Example:
Formula in H3:
=SUMPRODUCT(((A2:A7=G1)+(A2:A7=H1)+(A2:A7=I1)+(A2:A7=J1))*(B1:E1=G3)*B2:E7)
Formula in H4:
=SUMPRODUCT(MMULT(--(A2:A7=G1:J1),ROW(1:4)/ROW(1:4))*(B1:E1=G4)*B2:E7)
To be complete, there also would be an approach using SUMIF inside SUMPRODUCT which would be the better approach in my opinion.
So the Formula in H4 would be:
=SUMPRODUCT(SUMIF(A2:A7,G1:J1,INDEX(B2:E7,0,MATCH(G5,B1:E1,0))))
Your formula would be:
=SUMPRODUCT(SUMIF(A2:A462,AC1:BD1,INDEX(B2:AA462,0,MATCH("June",B1:AA1,0))))

Return Value in a column based on value in a subset in another column

I'm working on taking information from a table like so:
A 1
2
B 3
1
4
C 2
5
Essentially, a series of sets (A,B,C) with their elements arranged vertically beside them.
What I'm trying to do is retrieve the list of column 1 values that have a certain value in column 2. For instance, if the lookup value for column 2 was 1, I would want A and B to match, but not C. Best case scenario, I could generate a new column containing the matches. Is there a way to do this without resorting to VBA?
EDIT:
The data I am working with is not so clean, here's a doctored version of it
1 2 3 4
83 Fun Edit ZZZZZZ*AAAAAA 210
365,400 176
210
85 Fun Edit 600,500 205
MEDICARE[705] 176
200
The extracted data does not like to preserve relationships between data beyond the column 1 identifier. In this case, the information in column 3 "###, ###" comes from item 176 in column 4. So filling down and taking the row will result in issues downstream.
In the long run, the data in column 4 is just a key for matching the information in this extract with another one.
I appreciate everyone's help thus far, and apologize for my insufficient original example.
Here's a short workflow that will do it:
Select the entire range
Press Ctrl+G (Goto)
Click Special
Tick Blanks and OK
Type = and arrow up. You should have a formula that looks like =A1
Press Ctrl+Enter. At this point all the missing alpha values should be filled in.
Apply Autofilter and filter the numbers to show only 1
If you want to use the filtered alpha list elsewhere, copy the values showing, and paste elsewhere.

excel 2007 X Y lookup

Good morning. I have been searching for some code either a formula or VBA to lookup values in a table. I have two tables that I am looking to migrate data from the old with the new. Both tables are relatively the same.
A B C D E
1 Store 1234 2345 3456 4567
2 1234 0 5 10 15
3 2345 5 0 20 25
4 3456 10 20 0 35
5 4567 15 25 35 0
It is basically a mileage table with location to location distance. I am looking for a way to take the values from the old table into the new when the row columns dont match up exactly due to new locations added.
I know how to do a vlookup, but that dosent do what Im looking for... I want a way for a formula or vba to something like "find Value in B2 "1234" where it intersects the value in D1 "2345" = D2 "5"
Should be able to do a Index and Match combo to find it. I1 = From, K1 = To you can just type in the locations into those cells and get the range out you want.
=INDEX(A1:E5, MATCH(I1,A1:E1,0), MATCH(K1,A1:A5,0))
Can you implement IF formula to vlookup? In abstract: =IF((vlookup)=something),do this, else)
I would be hapy to look into this issue further, if you could provide complete BEFORE data and expected AFTER data.
Also, maybe =DGET would work for you?
I used this formula slightly modified and it worked fine,
=INDEX($A$1:$G$7, MATCH(B12,$A$1:$A$7,0), MATCH(C12,$A$1:$G$1,0))
the first part of the equation is the entire table including the X and Y coords. the next two parts are the X and Y coords (you can swap these round if you wish)
so the requested information for x and y was put in cells C12 and B12 and all those cells below...
then I used the dollar symbol to fix all the other look up cells, so i could use auto fill, and entered this in E12 (this is where the result will appear.
You can see the table in the attached (or could if I was allowed to attach it). I am looking up B12 (3) in column A then looking up C12 (6) in row 1 and returning the value at the intersection (in this case returns "r").
or there would be an attachment if the stupid web page did not insist on having me obtain a 10 reputation... hopefully you get the idea...

Excel: need help with unusual lookup function (sorted column is different from lookup column)

I am having trouble constructing a unusual lookup formula in Excel.
Normally, I would use VLOOKUP(), but the pitfall is that I want to look up a number in a column from a table that is sorted on an other column. Vlookup can only lookup things on the sorted column itself.
The scenario is as follows:
The table is sorted ascending on column B.
For a given parameter P, I now want to find the first A value, starting from the top and going down, that is bigger than or equal to that parameter P.
The function should then return the corresponding B value.
Table(part off, the complete table is much bigger):
A B
1 640 4.5
2 1600 7.0
3 640 7.5
4 1280 12.0
5 1920 16.5
6 2560 21.0
7 1600 19.8
8 3200 26.8
9 4800 33.8
For example, say my parameter is 1100, then I want my formula to return 7.0, because the first entry when searching downwards in column A that is bigger than or equal to 1100 is 1600, which has a corresponding B value of 7.0
I've tried my luck with Array Formula's (also known as "ctrl-shift-enter formula's") and constructed something like this:
{=INDEX(table;
MATCH(MIN(IF(columnA-$C1>=0;columnA;FALSE));
IF(columnA-$C1>=0;columnA;FALSE);
0);
2)}
with C1 containing my parameter, table the range A1:B9, and columnA the range B1:B9
But that doesn't work (in the example above, it returns 12.0 because 1280 is selected by the MIN() function) .
Solution I don't want to use:
I could write some VBA could to go through the table, but I don't want to do that (because of annoying 'macro warnings', and because Excel on Mac doesn't support VBA anymore)
Anybody any clues?
You can use
{=INDEX(B1:B9,MIN(IF(A1:A9>C1,ROW(A1:A9),FALSE)))}
Note that I am using English UK language settings - you will have to alter the formula to match your locale, replacing commas with semi-colons, etc.
If you didn't want an array formula you could try =OFFSET($C$5,MATCH($A$17,B5:B13),0) where C5 is the start of you B column, B5:B13 is you A column and A17 is you value to match against.
Ninja edit: Here is a version which works for the less-than or equal-to bit of your specification.
=OFFSET($C$5,IF(ISNA(MATCH($A$17,B5:B13,0)), IF(ISNA(MATCH($A$17,B5:B13)),0,MATCH($A$17,B5:B13)), MIN(MATCH($A$17,B5:B13,0)-1,MATCH($A$17,B5:B13))),0)
Assuming the data table is in range A2:B10, with the value you're searching on in cell B1, the following seems to work:
=IF(B1<A2,B2,IF(ISNA(VLOOKUP(B1,$A$2:$B$10,2,FALSE)),INDEX(B2:B10,MATCH(B1,A2:A10)+1),VLOOKUP(B1,$A$2:$B$10,2,FALSE)))
I edited this to account for when the lookup value is smaller than any of the values in the list.

Resources