Sheets lookup based on 2 columns - google-sheets

I am trying to figure a way to search based on a name in column A and date in column B what is the salary of that person. The salaries are in another worksheet, also split by the name in column A and date in column B and salary in column C.
I am doing this in Google Sheets.
Below is shown what I need.
Table 1:
Name
Date
Salary
John Smith
31/12/2020
$5,000
John Doe
31/12/2020
$4,500
John Smith
31/11/2020
$4,780
Table 2:
Name
Date
Salary
John Smith
31/12/2020
=formula here to find appropriate salary

You can try QUERY() function in google sheet.
=QUERY(A2:C4,"Select C Where A='" & A9 & "' AND B='" & B9 & "'")
You can also use INDEX/MATCH() like
=ArrayFormula(INDEX(C2:C4, MATCH(A9&B9,A2:A4&B2:B4,0)))

use:
=INDEX(IFNA(VLOOKUP(A2&B2, {'Table 1'!A:A&'Table 1'!B:B, 'Table 1'!C:C}, 2, 0)))

In google sheets you can try:
=FILTER(C1:C3,A1:A3=E2,B1:B3=F2)

Related

How to extract unique rows based on a criteria across different sheets on Google Sheets

I have a main sheet with a lot of data but here it is simplified:
Manager
Employee
Project
Date
John
James
Pineapple
1/1/2021
John
James
Banana
1/1/2021
Alex
Robert
Apple
1/1/2021
Sally
Mindy
Kiwi
2/1/2021
Sally
Mindy
Orange
1/1/2021
Sally
Matthew
Tomato
2/30/2021
Sally
Mindy
Grape
1/1/2021
John
Vlad
Orange
2/30/2021
I tried using a formula that looks like this:
=ARRAYFORMULA(INDEX($B$2:$B,SMALL(IF($A$2:$A=B$1,ROW($A$2:$A)-MIN(ROW($A$2:$A))+1,""),ROW(B2))))
However it's not working.
I got the =UNIQUE() for each person from column A:
UNIQUE
John
Alex
Sally
I transpose this into their own columns:
John
Alex
Sally
and then I want a formula under each name that will go through the range that I specify
John
=UNIQUE() for column B "Employee" based on the criteria "John" in column A
=COUNTIF()
James
2
Vlad
1
And this would be useful to figure out the projects based on the criteria of column A "Manager"
John
=UNIQUE() Column C "Project"
=COUNTIF()
Pineapple
1
Banana
1
Orange
1
What's the best way of organizing this?
try:
=QUERY({A2:C}, "select Col3,count(Col2) where Col3 is not null group by Col3 pivot Col1")

Use COL name to Get ROW names based on whether a value exists in a Column with the specified Name

Would deeply appreciate it if anyone could help me with this.
Overview
In a google sheet I have the following grid:
School A
School B
School C
Tim
x
x
John
Martin
x
x
Jack
x
The Rows are Names of people who cater to certain schools. The value 'x' in the cell simply signifies the relation. So Tim caters to School A & School C and similarly Jack only caters to School C.
Note: The cells are either empty or contain that 'x'. Thought that might help. We don't really need to look for 'x' just a non-empty cell.
Question
I have another table like follows, where I have a School column listing all the schools in rows. I would like to create a formula to use the table above and return a concatenated string listing all the people catering to that school.
School
People
School A
Tim, Martin
School B
Martin
School C
Tim, Jack
use:
=INDEX(REGEXREPLACE(TRIM(SPLIT(FLATTEN(QUERY(TRANSPOSE(QUERY(QUERY(SPLIT(FLATTEN(
IF(B2:D="",,B1:D1&"♠♦"&A2:A&",♦"&A2:A)), "♦"),
"select Col1,max(Col2) where Col2 is not nUll group by Col1 pivot Col3"),
"offset 1", 0)),,9^9)), "♠")), ",$", ))
or:
=INDEX(REGEXREPLACE(TRIM(SPLIT(FLATTEN(QUERY(
{B1:D1&"♦"; IF(B2:D="",,A2:A&",")},,9^9)), "♦")), ",$", ))

Return the Sheet Name on a Query Formula

My company got the timesheet of all employees in a google sheet where each employee registers their time. Each employee has his separated sheet with the same columns (Date, Time, Project and Notes) and the name of the sheet is the name of the employee.
I did a query function of all sheet to return all hours register to a project in a time period and the query returns all hours (lines) reported by the employees.
=Query({employee1!A2:F;employee2!A2:F;employee3!A2:F;employee4!A2:F};"select * where Col2 Matches '"&I1&"' and Col1>=date '" & Text (L1;"yyyy-mm-dd")&"'and Col1<=date '" & Text (M1;"yyyy-mm-dd")&"'")
But I need to also know the employee that register that time that is the sheet name. So, my question: how I add the sheet name in the query, so it returns the name of the employee that reported the time on that project? For each row I must add the employee.
Here is an example: https://docs.google.com/spreadsheets/d/1rgA1aygOhaLQ7WP8wUjr5YCEENDQqJpFR3cSXhLSvJw/edit?usp=sharing
Thanks in advance for your time and be safe.
try:
=ARRAYFORMULA(QUERY({
{Employee1!A2:F, "employee1"&Employee1!Z2:Z};
{Employee2!A2:F, "employee2"&Employee2!Z2:Z};
{Employee3!A2:F, "employee3"&Employee3!Z2:Z};
{Employee4!A2:F, "employee4"&Employee4!Z2:Z}},
"where Col2 matches '"&I1&"'
and Col1 >= date '"&TEXT(L1, "yyyy-mm-dd")&"'
and Col1 <= date '"&TEXT(M1, "yyyy-mm-dd")&"'"))

Google Sheets formula to compare data in a single cell with multiple cells and return a value based on those cells

Currently, I have sheets document that compares cell name containing a last name field with a column of data elsewhere and returns a third column's value when it matches. I have posted an example below
i.e.
Here is the formula ||| Lookup(A1,'Sheet 2'!B:B,'Column C'!C:C)
Sheet One with Formula Sheet 2:
Column A Column B Column A Column B Column C
Smith 111111 Oscar Smith 111111
The problem is if there are 2 smiths it only grabs the first one.
What I want to do is use the first initial. last name in sheet one and compare to column A and B to return Column C.
Sheet One with Formula Sheet 2
Column A Column B Column A Column B Column C
O. Smith 111111 Alex Smith 222222
Oscar Smith 111111
I am stuck...
Here is a link to help out. https://docs.google.com/spreadsheets/d/1m087VIKk_F8OUbKy2wMvb12DM9fg9r0YIlbU24QHsSY/edit?usp=sharing
In B3 of Sheet 1 I entered this formula
=ArrayFormula(if(len(A3:A), vlookup(A3:A, {Left(Sheet2!A2:A)&". "&Sheet2!B2:B, Sheet2!C2:C}, 2, 0),))
See if that works for you ?
JPV also informed me that Lookup requires content to be in alphabetical order. If I would have used Vlookup I could have pulled the data using the concatenation method I was trying out.
Concatenation formula: =Left(A2,1)&". "&B2
Working Formula - vlookup(A1,'Sheet 2'!B:B,'Column C'!C:C)
Sheet One with Formula Sheet 2:
Column A Column B Column A Column B ColumnC Column D
A. Smith 222222 Oscar Smith O.Smith 111111
Anthony Smith A. Smith 222222

Consolidate two ranges in date wise order in google spreadsheet

I am knew to google spreadsheet and trying to unite/consolidate two ranges in order, I am struggling hard with this & have written formula on spreadsheet but that is wrong.
Two Ranges are:
Range-1 = D1:F12
D1:D12 E1:E12 F1:F12
Word Date Name
Range-2 = G1:I12
G1:G12 H1:H12 I1:I12
Word Date Name
Now I want to unite/consolidate Range-1 & Range 2 where words should appear in column A, Date should appear in column B & Name should appear in column C & criteria is that date of new range should be in ascending order.
You may please see below mentioned link:
https://docs.google.com/spreadsheets/d/1tiKUdREYudh1htLIfh9VSWO27N5zCXwJAVKr0gqaSXE/edit#gid=0
Please help, thanks in advance.
try:
=query({D1:F; G1:I}, "where Col1 <>'' ")
and see if that works.
If you need it ordered by date:
=query({D1:F; G1:I}, "where Col1 <>'' order by Col2")

Resources