Google Sheets formula to lookup value for all rows in another sheet by column names and returning value by column name - google-sheets

I have a Sheet1 with data like this:
one
two
three
four
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
I have Sheet2 with data like this:
alpha
value 1
c
k
g
c
For each row in Sheet2, I want to look up Sheet2.A2:A in Sheet1 according to a lookup column name in Sheet1 and returning values from the associated row in Sheet1 by return column name in Sheet1.
So, a few examples:
Lookup Sheet2.A2:A in Sheet1.three and return Sheet1.one
Lookup Sheet2.A2:A in Sheet1.two and return Sheet1.four
The idea is the formula would specify the lookup column name and return column name and I'd just change it for each lookup I need to do.
Imagine the formula was something like:
=ARRAYFORMULA(
SOMEFORMULA(
A2:A, # lookup this value
GETCOLUMN(Sheet1, "three"), # in this column in Sheet1
GETCOLUMN(Sheet1, "one") # and return the value from this column in Sheet1
)
)
So, the expected result is:
alpha
value
c
a
k
i
g
e
c
a
I can use the new Google Sheet formulas they just released -- except named ranges. I feel like there is some clever trick using them, but I can't come up with it.

Give a try on below formula:
=BYROW(A2:INDEX(A2:A,COUNTA(A2:A)),LAMBDA(x,INDEX(Sheet1!A:D,MATCH(x,INDEX(Sheet1!A:D,,MATCH("three",Sheet1!A1:D1,0)),0),MATCH("one",Sheet1!A1:D1,0))))
By XLOOKUP() function.
=BYROW(A2:INDEX(A2:A,COUNTA(A2:A)),LAMBDA(x,XLOOKUP(x,FILTER(Sheet1!A2:D,Sheet1!A1:D1="three"),FILTER(Sheet1!A2:D,Sheet1!A1:D1="one"),"")))
Sample Sheet Link.

Use HLOOKUP to the get the correct column in Sheet1 and XLOOKUP to get the corresponding column A value:
=ARRAYFORMULA(
XLOOKUP(
A2:INDEX(A2:A,COUNTA(A2:A)),
HLOOKUP("three",Sheet1!A1:Z,SEQUENCE(ROWS(Sheet1!A1:Z)),0),
Sheet1!A1:A
)
)

Related

How to prevent duplicates between two different sheets on google sheets?

I have 2 sheets, one is sheet1, other is sheet2.
Data in sheet1
Name
A
B
C
D
E
L
M
N
O
P
Data in sheet2
Name
F
G
D
H
G
Here in sheet2, two data is duplicated. One is "D" compared to sheet1, other is "G" in same sheet2.
I want to prevent duplication in both these cases so that whenever I enter new value in sheet 2, it must check both the sheets and reject duplicate entries.
I am using Google Sheet, and using data validation with a custom formula =COUNTIF(sheet1!A2:A&sheet2!A2:A,Sheet2!A2)<2
But, it's not working. Please help me.
Try with:
=COUNTIF({sheet1!$A2:$A;sheet2!$A$2:$A},Sheet2!A2)>1
With curly brackets you can join the ranges

VLookup Displaying Duplicate Values - Google Sheets

I've created a lookup formula to take values from column E, match them with values in column A, and assign the corresponding value found in column C and populate it in column F.
I've checked for duplicates in E and A, but I'm still seeing duplicates in F. It's not because there isn't a match, I've checked that as well.
My formula is:
=LOOKUP(E2, $A$2:$A$121, $C$2:$C$121)
Here is a simplified version of the spreadsheet: https://docs.google.com/spreadsheets/d/1A-S0nHFIUGycaDo7KDPAzWBwRZQmfxkjaMivwGfBh-8/edit?usp=sharing
delete everything in F column and use in F2:
=INDEX(IFNA(VLOOKUP(E2:E, A:C, 3, 0)))

Match Column A and B and return column C in same row as column B

I am trying to create and array formula that fill entire column C, and checks if cell from column A exists in column B then return value in column B in same row line.
PS: Column A has only first and last name, column b has full name, if column b contains column a then return b in same row line.
Sheet2:
Link to the sheet
Any help will be very much appreciated
What about if you try this:
=ARRAYFORMULA(IF(A2=B2,B2,""))
This will fill up C if A is matching in B and returns column B in C:

How to use Countif function to count rows that has a specific value in either of column A or B in Google sheet?

I am trying to count the number of rows that has a specific value let say "John" in either Column C or Column D. If the two columns have both the same value, then only one of them is counted.
Here is the example sheet. column C & D has the data.
Column G contains the function countif
https://docs.google.com/spreadsheets/d/1i9I2bhtlHAMWqVqdE7hbkgLRLCCUrfnOMSQcf9Gj4_0/edit#gid=0
Try:
=ArrayFormula(COUNTIF(C5:D12,F5:F7)-COUNTIFS(C5:C12,F5:F7,D5:D12,F5:F7))

Grouping Data with SUM of Value No Greater than a Specific Number (Google Sheets)

I have series of numbers as you can see in the following table in a Google Spreadsheet:
I want each name to form a group with other names next to it with sum of value no more than 26. If a sum is greater than 26, then it will be just forced to form to another group with another name.
So that it might look like this:
In this example, A and B can form a group together since the total sum of A and B is no more than 26. C is forced to form a group just by itself since if we add D with C, the sum will be more than 26. D is also forced to form a group just by itself since if we add D with E, the sum will be more than 26.
How can I create a table with Array Formula so it looks like that?
This is the link for the sample case:
https://docs.google.com/spreadsheets/d/1BXfJrfbtdsGP4fr9dsKxFq54nM4PnKLHauAOy5UAPbY/edit#gid=0
The sample case is in Sheet2
Column A and B are given condition
Column D to G are the desired outcome
Edited: sample case is changed from Sheet1 to Sheet2 so that the problem can be seen more clearly. Sheet1 is hidden to prevent confusion.
You can do it using two formulas:
for group in col G =ArrayFormula(IF(B2:B,INT(MMULT(TRANSPOSE((ROW(B2:B)<=TRANSPOSE(ROW(B2:B)))*B2:B),SIGN(B2:B))/26)+1,))
for group sum in col F =ArrayFormula(IF(LEN(B2:B),SUMIF(G2:G,G2:G,B2:B),))
or using one formula in col F which will be slower:
=ArrayFormula(IF(LEN(B2:B),{SUMIF(INT(MMULT(TRANSPOSE((ROW(B2:B)<=TRANSPOSE(ROW(B2:B)))*B2:B),SIGN(B2:B))/26)+1,INT(MMULT(TRANSPOSE((ROW(B2:B)<=TRANSPOSE(ROW(B2:B)))*B2:B),SIGN(B2:B))/26)+1,B2:B),INT(MMULT(TRANSPOSE((ROW(B2:B)<=TRANSPOSE(ROW(B2:B)))*B2:B),SIGN(B2:B))/26)+1},))

Resources