Match a unique column to two separate columns - arrays

I have one column in google sheet with unique values. I then want to match this column to two separate columns. See google sheet below for an example. I want the output in column "B".
[https://docs.google.com/spreadsheets/d/10AOYlqsScoDUfcOaJd2opjjC_8zXSOP3_HBTOCCrb6U/edit#gid=0][1]

You can use maxifs:
=maxifs($F$4:$H$14,$E$4:$G$14,A4)
A longer approach could be the following:
=max(vlookup(A4,$E$4:$F$14,2,false),vlookup(A4,$G$4:$H$14,2,false))

try:
=QUERY(FLATTEN(F4:F14, H4:H14), "where Col1 is not null")

Related

Stack multiple columns on top of eachother on Google Sheet?

I am using Google SpreadSheet, and I'm trying to import data from different sources together using a combination of query, importrange and curly brackets:
={Query(Importrange(SheetA),"select Col1,Col2,Col3,Col4 where Col1 is not null");
Query(Importrange(SheetB),"select Col1,Col2,Col3,Col4 where Col1 is not null")}
But the result formula only returns SheetA data.
Since I only need 4 particular columns from SheetA and SheetB, I'd want the columns from both sheets to stack on top of eachother like this:
Col1
Col2
Col3
Col4
Data SheetA
Data SheetA
Data SheetA
Data SheetA
Data SheetB
Data SheetB
Data SheetB
Data SheetB
I tried running each =query(importrange) individually and combine them afterwards using {A:D;E:H} but it gives Result was not automatically expanded, please insert more rows error.
I tried looking for other similar threads but they were mostly about stacking different columns into one singular column. Can you help me with my case?
first, you need to run every importrange separately as standalone formula to connect your sheets by allowing access
when done, only then, you can run this array:
=QUERY({IMPORTRANGE("url_or_id", "SheetA!A:D");
IMPORTRANGE("url_or_id", "SheetB!A:D")},
"where Col1 is not null", 0)
Turns out the issue was due to the infinite blank rows when trying to combine 2 infinite ranges A:D and E:H,
By enclosing them with a query, remove null value condition, my formula works fine now:
=query({A:D;E:H},"Select * where Col1 is not null")
Nevertheless, are there any ways to stack those 4 columns using the original singular formula using query, importrange and curly brackets?
={Query(Importrange(SheetA),"select Col1,Col2,Col3,Col4 where Col1 is not null");
Query(Importrange(SheetB),"select Col1,Col2,Col3,Col4 where Col1 is not null")}
Where you have 2 source files (Source1, Source2), and you want to use stack the data using IMPORTRANGE into another file (Combined)
There are 2 parts to this solution, and you can do Part 1 and Part 2 in any order.
Part 1
Give approvals to each of the imported ranges.
On a temporary sheet (that can be removed later) in the Combined file.
Use a standard IMPORTRANGE formula like this for Source1 (example, where you must replace "Source1_ID" with the ID of your Source1 file):
=IMPORTRANGE("https://docs.google.com/spreadsheets/d/Source1_ID", "Sheet1!A2:D")
After you have given approval, delete the formula from the cell, and do it again for Source2 (example, where you must replace "Source2_ID" with the ID of your Source2 file)
=IMPORTRANGE("https://docs.google.com/spreadsheets/d/Source2_ID", "Sheet1!A2:D")
Part 2
In the Combined file, go to the sheet where you want the combined data, and enter in the complete QUERY formula (example, where you must replace "Source1_ID" and "Source2_ID" with the ID's of both of your source files)
=QUERY({IMPORTRANGE("https://docs.google.com/spreadsheets/d/Source1_ID", "Sheet1!A2:D"); IMPORTRANGE("https://docs.google.com/spreadsheets/d/Source2_ID", "Sheet1!A2:D")}, "Select Col1, Col2, Col3, Col4 Where Col1 Is Not Null")
So we have 3 things to do:
Transpose so the columns are below the other.
Flatten so that it is ordered as necessary.
Filter to remove extra blank columns we selected.
This will work wonders considering the columns are different lengths and are already next to each other as in a table.
If columns are at multiple places use {A:A;D:D} to select columns and remove flatten and transpose.
=filter(flatten(transpose(A1:D10)), len(flatten(transpose(A1:D10))))

What is the best way for refactoring excel formula

Like I ask in title, what is the best way to write formula like this one below. I want sum from all sheets values for Germany (values are in B column)
=SUM(SUMPRODUCT(--(First!A2:A11="Germany"),(First!B2:B11)), SUMPRODUCT(--(Second!A2:A11="Germany"),(Second!B2:B11)), SUMPRODUCT(--(Third!A2:A11="Germany"),(Third!B2:B11)))
What is your opinion?
In Google Sheets you can also use
=QUERY({L1:M9;O3:P7},
"select sum(Col2) where Col1 ='xxx' label sum(Col2) 'Total' ",1)
(Please adjust ranges to your needs)
How the formula works.
We create an array using curly brackets {} stacking the ranges one on top of the other using semi-columns ; even from other sheets like {L1:M9;O3:P7;First!A2:B11;Second!A2:B11}. One can add as many ranges as needed. Even open ranges.
The ,1 in the end of the formula shows that the very first row will be treated as a header row.
Please read more about the QUERY. function
try:
=SUM(FILTER({First!B2:B11; Second!B2:B11},
{First!A2:A11; Second!A2:A11}="Germany"))
One more option:
=SUMPRODUCT(({First!A2:A9;Second!A2:A9}="Germany")*{First!B2:B9;Second!B2:B9})

Find and repeat a cell value if values match

My spreadsheet is collecting data from a form
On another tab I'm showing the responses that match "Lesson day" with "Today's date" (in the example, all the lessons are showed).
As you can see, the "e-mail" field is filled out only once.
Is there a way to automatically fill the "e-mail" field in the second tab? Maybe matching the "Student Code" with the "e-mail" fields in the first tab?
I've tried the MATCH() function but it returns only the position. I feel like I need to combine MATCH() with other functions but I have no idea about where to start
EDIT: Having the email adresses on another column would work too.
SOmething like: if the "Student Code" in the 2 tabs matches, show the email adress for that "Student code"
try:
=ARRAYFORMULA(IFNA(VLOOKUP(D4:D, FILTER({form!E2:E, form!G2:G}, form!G2:G<>""), 2, 0)))
change form to match the sheet name of your form sheet
As suggested, I created an auxiliary table (just called Sheet7) and getting closer to the desired result
In A column I used
=UNIQUE(Lessons!E:E)
In column B I used
=INDEX(Lessons!A:M, MATCH(A2,Lessons!E:E,0),7)
Then, on my second spreadsheet, I could get all the e-mail adress using the following formula
=INDEX(Sheet7!A:B, MATCH(D4,Sheet7!A:A,0),2)
I've tried to use ArrayFormula on the auxiliary table
ARRAYFORMULA(if(A2:A="",,INDEX(Lessons!A:M, MATCH(A2:A,Lessons!E:E,0),7)))
But it doesn't work. It shows only the email adress matched from the cell A2, ignoring A3, A4,...
A different approach:
Make an extra column in your form responses sheet called "Student E-mail".(In this example it is column "I")
In row 2 of that column, write the following formula:
=ARRAYFORMULA(IF(ISBLANK(G2:G),VLOOKUP(F2:F,INDIRECT("F$2:G"&ROW(I2:I),TRUE),2),G2:G))
Use that column for the emails in your other tab (hide the original email column)
Update:
Using array formula, you don't have to manually drag & drop. And it keeps going as new rows are added.
Usually MATCH is combined with INDEX
You should build an auxiliary table with one column for names and another for ee-mails.
To build the auxiliary table from the collected data you could use something like this
=UNIQUE(FILTER({Lessons!E:E,Lessons!G:G},LEN(Lessons!G:G)))
The above is better than using a formula for each column as this prevent having mismatching data.
INDEX / MATCH usually doesn't return the "expected" results in an ARRAYFORMULA. Instead use VLOOKUP.
NOTES:
Please bear in mind that every time that you edit a value the formula will be recalculated. If you have a lot of formulas (like when doing a fill down to copy a formula to all the cells in a column) or having an ARRAYFORMULA with open ended references i.e. G2:G this could affect your spreadsheet performance.
If you go for using an ARRAYFORMULA, use ARRAY_CONSTRAIN to limit the number of rows returned by your formula.
Related
How to map values between columns in worksheets

Google Sheets linking two sheets using a primary key

I have two sheets that I want to link using a "primary key". At the moment, I have imported from sheet1 into sheet2 some columns using the function
=Sheet1!A1 (for the first cell for instance). My purpose is to complete the data related to each imported line in sheet2. However, sheet1 is shared with other people, thus they can modify the content of a line without deleting or modifying the data I have added in sheet2 (and that doesn't exist in sheet1).
Given the fact that my table has a column 'id' that can be considered as a primary key, how can I add new data in sheet2 in so far as it will be related to the 'id' rather than the position of the line (so if I ever change an id in sheet1 the data I added will be deleted or if I move an id to another line, all the data will be moved too)?
you can use VLOOKUP and bring over data based on ID, like:
=ARRAYFORMULA(IFERROR(VLOOKUP(D:D, Sheet1!A1:B, 2, 0),))
for more columns add them in an array:
=ARRAYFORMULA(IFERROR(VLOOKUP(D:D, Sheet1!A1:B, {2,3,4,5}, 0),))
demo spreadsheet
I like player0's answer, but I found this easier to understand:
=QUERY(data_to_search,"select column_you_want_to_show where other_sheets_primary_key_column='"&this_sheets_primary_key_column&"'")
e.g.
=QUERY(Sheet4!$A$2:$F$10,"select F where A='"&$A2&"'")

ssrs: one static row matrix, multiple columns will not filter out nulls

Using a ssrs 2005 matrix client side. I want to list the multiple addresses of one person, hence one row, multiple columns. The Column field is =Fields!StreetName.Value. The data details field is =First(Fields!StreetPrefix.Value) & " " & First(Fields!StreetName.Value). The datasource has a row for each address; however, some rows will have nulls since the datasource is composed of outer joins.
The column grouping works, but the first column is always empty, (first 2 rows of datasource are null) addresses appear only after the empty column. I want to filter out nulls on the matrix, but its like the filter is ignored. I have also tried having the dataset return an empty string for a null streetname and setting the filter to =Fields!StreetName.Value != ="" but no difference.
What am I missing?
Is it not better that you filter your rows in your query? maybe this solution is better.
Have you got the filer in the right place? You can put it on the matrix and on the group.

Resources