I have two sheet of excel exported from a database with hundreds of rows.
In first sheet I've these columns
name age gender
id1 23 m
id2 45 f
In second sheet these columns
id1 john smith
id2 jean ford
I'm looking for a macro or somethig else to automatically replace the idx in first sheet with the corresponding values from second sheet.
The final result should be a sheet like:
name age gender
john smith 23 m
jean ford 45 f
You don't need anything as complicated as a macro-- VLOOKUP will suffice:
Searches for a value in the first column of a table array and returns
a value in the same row from another column in the table array.
The V in VLOOKUP stands for vertical. Use VLOOKUP instead of HLOOKUP
when your comparison values are located in a column to the left of the
data that you want to find.
For example, if your id-sheet mapping was on Sheet2, then the formula
=VLOOKUP(A2,Sheet2.$A$1:$B$2, 2)
would look for the value found in this sheet's A2 cell in the leftmost column of the data table located in Sheet2.$A$1:$B$2, and then return the value from the 2nd column of that table. Copy that downwards, and get something like
Related
I am trying to perform an index and match formula in Excel with a two large datasets which will return multiple unique results.
I have illustrated a simplified version of the data below. The two match conditions are A1 in table 2 = A:A in Table 1 and B2 in table 2 = B:B in table 1. This will result in multiple results and I want a formula I can drag from cells C3 across to D4 in table 2 to show the results of this index and match.
Table 1
First Name
Second Name
Food allergy code
Bob
Johnson
03
Bob
Johnson
04
Table 2
First Name
Second Name
Food allergy code 1
Food allergy code 2
Bob
Johnson
03
04
I have used the formula below which returns the first match, but when I drag this from cell C2 to D2 it returns the same value. I'm not sure how to rewrite this formula so that it provides each unique Food allergy code given both match conditions are met.
=TRANSPOSE(INDEX(Table1!C:C,MATCH(1,(Table1!A:A=A2)*(Table1!B:B=B2),0)))
Any help would be appreciated.
You could use the following, but it is computationally rather inefficient, so if you want to drag this formula over many cells, you should leave a comment to find a computationally more efficient solution.
=TRANSPOSE(FILTER(D:D,(B:B=G4)*(C:C=H4)))
which looks like this in an example:
I have a google sheets document that has a main sheet which will have columns x y and z and subsequent sheets 1, 2, and 3 that will each also have columns x y and z. Sheets 1, 2, and 3 represent different people who are putting information into the columns.
The purpose of the main sheet is to display all of the information that has been put into columns x y and zin the three other sheets so the information can be viewed all at once. The purpose of sheets 1, 2, and 3 is so each individual can track their own individual information without also seeing all the info from other people/sheets.
I would like to be able to automatically pull new information from sheets 1, 2, and 3 and have it placed in the respective column on the main sheet in chronological order. I know it is possible to have specific cells display information on another sheet, but if possible, I would like the cells to automatically populate the next available cell in whichever column they are under. Basically, the columns in the main sheet and the other three sheets are the same name, and I would like the columns in the main sheet to populate whenever new info is input to the respective columns in sheets 1, 2, and 3. I hope this makes sense.
For instance, if column x in sheet 2 was filled in with the name Jane Doe, the main sheet should automatically populate Jane Doe into the next available cell in column x. Then someone types in John Smith into column x on sheet 1 and it automatically populates the cell after Jane Doe with John Smith in the main sheet.
Here is a demo sheet with how I would like it to be, with the columns in the main sheet populated with the items in all the columns from sheets 1, 2, and 3: https://docs.google.com/spreadsheets/d/1y0dldFtq6NtLPjU21HVedtUzYKi-MjLTz62tupYbZGY/edit?usp=sharing
Is it possible to connect sheets within a document like this? Thank you so much in advance! :) Let me know if you need any more information.
with formulae, you have two options on chronology:
sheet-by-sheet
=QUERY({Sheet1!X:Z; Sheet2!X:Z; Sheet3!X:Z},
"where Col1 is not null
or Col2 is not null
or Col3 is not null", )
row-by-row
=QUERY(SORT({
Sheet1!X:Z, ROW(Sheet1!X:Z);
Sheet2!X:Z, ROW(Sheet2!X:Z);
Sheet3!X:Z, ROW(Sheet3!X:Z)}, 4, 1),
"select Col1,Col2,Col3
where Col1 is not null
or Col2 is not null
or Col3 is not null"; )
the next best thing is to have a timestamp script with onEdit trigger so every time your ppl make a change a timestamp is added on their sheet in some column and then you in your master sheet will only collect it and sort by timestamp.
https://stackoverflow.com/questions/tagged/google-apps-script+timestamp
I have two sheets, sheet1, and sheet2. Column E of sheet2 contains a quantity and column K contains a text string (i.e. a key). Multiple rows in sheet2 contain the same text string with different quantities.
On sheet1 column B, I have a list of text strings. For each text string, I want to query sheet2 and sum up all the quantities in its E column where the value in the K column matches the text string.
Currently, I need x queries where x is the number of text strings in column B of sheet1.
Each current query in sheet1 looks like this:
Query in sheet1 cell A1 using text string in B1 of sheet1
=SUM(
QUERY(
'sheet2'!$A$2:INDIRECT(CONCATENATE("'sheet2'!O",'sheet2'!P1)), "select E where K="""&B1&""""
))
Query in A2 using text string in B2 of sheet1
=SUM(
QUERY(
'sheet2'!$A$2:INDIRECT(CONCATENATE("'sheet2'!O",'sheet2'!P1)), "select E where K="""&B2&""""
))
and so on...
Cell P1 of sheet2 contains the number of non-zero rows in sheet2
This works well, but the problem is that sheet2 contains 200,000 rows.
I have around 100 text strings to search for, so I am currently using 100 queries, each of which looks at 200K rows x 15 columns = 3 Million cells
Understandably it takes a long time for the sheet to update as all these queries re-run when sheet2 is updated.
Is it possible to consolidate all of these queries to one? In other words, tell the formula "I want you to perform the sum-query using each cell in the range B1:B100 as the variable x for K=x in the query and place the results in cells A1:A100 respectively"?
in some cases putting it into array may boost a bit the performance:
={SUM(QUERY('sheet2'!$A$2:INDIRECT(CONCATENATE("'sheet2'!O", 'sheet2'!P1)),
"select E where K="""&B1&""""));
SUM(QUERY('sheet2'!$A$2:INDIRECT(CONCATENATE("'sheet2'!O", 'sheet2'!P1)),
"select E where K="""&B2&""""))}
however, too many QUERY functions should be avoided to prevent the halt. the best performance belongs to DGET and alternatives include FILTER and SUMIF
This I hope as your single query, B8 must be change to the last row in sheet1
=arrayformula(vlookup({Sheet1!B1:B8},QUERY(Sheet2!A1:K,"select K, sum(E) where K<>0 group by K "),2,false))
BACKGROUND (simplified version): I’m sorting data sheets of different items for our lab. I have one sheet that lists the code number of the item (column A) with the actual name of the item (column B), for example
code | item
001 | Banana
002 | Cabbage
003 | Carrot
004 | Peach
and another sheet (labelled stocks) that lists only the code number (column A) and the amount of stock we have for that item (column B), for example
code | stock
001 | 5
002 | 6
003 | 2
004 | 7
PROBLEM: Now, these items can be sorted into 2 categories, “fruits” and “vegetables”. I can easily sort the items in the item sheet manually because I can see the actual item name, but for the stock sheet, only the code number is listed which means I would have to keep looking at the other sheet to see which item is associated with a particular code.
I already have separate item sheets for fruits and vegetables, so I have three sheets total now: fruits, vegetables, and stocks.
I was thinking of an IF statement to be placed in the stocks sheet that would indicate if the item is a fruit or a vegetable. Something like: if the code in A1 of the “stocks” sheet is present in column A of the “fruit” sheet, then print the word “fruit” in C1 of the “stocks” sheet. If not, print the word “vegetable” in C1.
My ultimate goal (what the lab is looking for) is that I would have separate item sheets for fruits and vegetables (already done) and also separate stock sheets for fruits and vegetables (to be done).
Would appreciate any help. Many thanks
VLOOKUP works well for this.
Make a third column in the stock sheet with the following formula in Cell C2 and copy it down to the cells below:
=VLOOKUP(A2,Fruits!$A$2:$B$200,2,FALSE)
This takes the value in cell A2, find the same id in the table in sheet 1 and returns the value that is given in the 2nd column of the Fruit Worksheet.
If you want the tables fruits and vegetables separate. You can use IFNA to find the id in the second worksheet as followed:
=IFNA(VLOOKUP(A2,Fruits!$A$2:$B$200,2,FALSE),VLOOKUP(A2,Vegetables!$A$2:$B$200,2,FALSE))
if the code in A1 of the “stocks” sheet is present in column A of the “fruit” sheet, then print the word “fruit” in C1 of the “stocks” sheet. If not, print the word “vegetable” in C1.
This is a simple test across the worksheet. This formula searches range A:A in the "Fruit" sheet, and if there is a match (returned as a number) it gives the first value "Fruit", otherwise it will return "Vegetable".
=IF(ISNUMBER(MATCH(A1,Fruit!A:A,0)),"Fruit","Vegetable")
However be careful with this, because if the code is wrong of not found, it will return "vegetable" by default. To get around this, use a nested IF statement which checks both sheets like so, and returns "Not found" if the code is wrong.
=IF(ISNUMBER(MATCH(A1,Fruit!A:A,0)),"Fruit",IF(ISNUMBER(MATCH(A1,Vegetable!A:A,0)),"Vegetable","Not found"))
EDIT: I've swapped the SEARCH for the more powerful MATCH since this will negate display options and still find the correct sheet.
I would like to retrieve average daily milk from sheet 1 to sheet 2. Each row has a unique identification number. The average daily milk data exported to sheet 2 is linked to the unique ID Nr. In sheet 1 there are many more unique ID.Nr ( Rows) present than in sheet 2. How do I transfer the data from sheet 1 to sheet 2 in exact correlation to identification nr, without sorting the rows?
I have tried vlookup function but result is always NA. I belive it should be an array function, as it has too look for ID Nr. and cannot use position of cell.
Table Sheet1 is on a different Worksheet than Sheet 2 but on same File.
Vlookup should work just fine. The only thing is that you have to make sure that the Id Nr. in both sheets are the same type (In this case both should be strings since they have "_" in the text). This is how you should use the vlookup:
=VLOOKUP(A2,Sheet1!A:B,2,FALSE)
And then copy the formula all the way down in column B of sheet2
The solution is to use the index match function. The advantage in comparison to an lookup function is that it handles great amount of data better and also the reference number does not need to be on the far left column.