Google Sheets: Many to Many Table Join - google-sheets

I am trying to create a sheet to determine the amount of overlapping hours for employees.
I have one table with timeclock data for the Employees.
Table 1
And another with timeclock data for their Support Staff.
Table 2
This is the desired output. Each row from table A has all the date matches from table B. From here I would compute the number of overlapping hours in the final column and then roll that up into another sheet.
Table 3, Desired Output
(apologies for image links, I can't post inline images yet)
Sample sheet here Please let me know if you have any ideas for me!
I know its a combination of QUERY, ARRAYFORMULA, FILTER and more but I just can't find the right combo.

Here's a way of doing this type of join using only built-in functions:
=arrayformula(lambda(employee,support,
lambda(datecomp,
lambda(rows,
{vlookup(index(rows,,1),{row(employee),employee},sequence(1,columns(employee),2),false),
vlookup(index(rows,,2),{row(support),support},sequence(1,columns(support),2),false)})(
split(filter(datecomp,datecomp<>""),"|")))(
flatten(if(index(employee,,1)=transpose(index(support,,1)),row(employee)&"|"&transpose(row(support)),))))(
Employee!A1:D6,Support!A1:E5))
There's a lot going on here, but the basic idea is that we are comparing the date columns of each table against each other in a 2D IF array, and where the dates match we are obtaining the row index of each table. After some manipulations we can use these row indexes on each table in two side-by-side VLOOKUPs to obtain the joined table.

DMac,
I wrote myself a QUERY replacement custom function that uses real SQL select syntax.
For your data it looks something like (You need a tab called employee and a tab called support for this to work) :
=gsSQL("select * from employee full join support on employee.date = support.date")
See my test worksheet: (line 164 on gsSqlTest sheet)
https://docs.google.com/spreadsheets/d/1Zmyk7a7u0xvICrxen-c0CdpssrLTkHwYx6XL00Tb1ws/edit?usp=sharing
You need to add one Apps Script file to your sheet to give you the custom function:
https://github.com/demmings/gsSQL/blob/main/dist/gssql.js
For more help using more features see:
https://github.com/demmings/gsSQL
For example, changing the column titles, it would be like:
select employee.name as name .... (rest of your select).

Related

Querying helper table within Google Sheets

I want to import central banks interest rates into google sheets. The table I'm using can be found here:
=importhtml("https://www.investing.com/central-banks","table",1)
For each items that I want from this table, I would have a function like (in this example, to fetch 1.00%):
=value(substitute(index(importhtml("https://www.investing.com/central-banks","table",1),2,3),",",""))
If I need this whole table, which consists of 12 rows (excluding header) x 4 columns, I would have 48 such formulas. It seems to me that:
this is messy, and
making 48 calls to the investing.com URL where one could probably suffice.
So I decided to try a different approach. In another tab of my google sheets, I call the whole table:
In my other tab, I thought to query this table (assume it is in a tab called rates) instead. But I don't know how. Is there a way, and if so, what is the correct way to query say:
the first name in the table (Federal Reserve (FED))?
the fourth interest rate in the table (-0.75%)?
Any help is greatly appreciated.
To get 1%, try
=index(importhtml("https://www.investing.com/central-banks","table",1),2,3)
index
adapt parameters to fetch
the first name in the table (Federal Reserve (FED)) =index(importhtml("https://www.investing.com/central-banks","table",1),2,2)
or the fourth interest rate in the table (-0.75%) =index(importhtml("https://www.investing.com/central-banks","table",1),5,3)
To get all % per banks at once
=query(importhtml("https://www.investing.com/central-banks","table",1),"select Col2,Col3",1)
The answer he gave you Mike Steelson is good, but if I were you, I would make it in such a way that I could change the parameters at any time
=query(importhtml("https://www.investing.com/central-banks","table",1);"select Col2 WHERE (Col3='"&$A1&"')",1)
where A1 = 1.00% or any number entered into that cell

Count specific words in table for each row that begins with a cell of a certain value (Google Sheets)

That's about as clear as I make what I'm trying to do in Google Sheets.
Here's a sample table with two tabs.
Tab 1
Basically, I've got a table fed from a form. One column has names of say 50 various people. The names repeat randomly.
Other columns contain comments that each person made.
Tab 2
Here is essentially a heat map of keywords used by the different people. Column A are the keywords, while row 1 contains the keywords I'm interested in.
Each cell in this grid should (1) search tab 1 for all instances of each name, then (2) count the number of times the keyword appears in all of that person's comments.
Countifs doesn't work because the array arguments are different sizes.
I can't figure out how to phrase a filter embedded in a countif.
And using QUERY seems like it will cause trouble because my actual spreadsheet is something like 100 names and 40 keywords.
I'm open to suggestions and grateful for your help!
ken.
In B2 try
=sum(ArrayFormula(--regexmatch(filter(Sheet1!$B$2:$F, Sheet1!$A$2:$A=B$1), "\b"&$A2&"\b")))
Then fill down to the right and down as far as needed.
To make the match case-insensitive, change "\b"&$A2&"\b" to
"\b(?i)"&$A2&"\b"
See if that works?

Display columns of information in Google Sheets based on Drop down selection

What I am looking to do is have a list of items in a dropdown list in cell A1. Lets say the list is "Presidents, Movie Stars, Rappers".
When I select Presidents I want Column B in Sheet 1 to list all the presidents with column C listing their party they represented and column D to list their years in office. When I select Movie stars I want column B to List various Movie Star names, Column C to list number of movies starred in and Column D to display their highest paid film.
So in short I want 1 dropdown to populate 3 columns worth of data.
Everything I have looked up uses scripts(which I think this is completely doable without using) uses VLOOKUP but has 1 cell worth of data appear(ex, A1 dropdown displays data in A2 but not data in B1:B50, C1:C50, and D1:D50) or doesnt worth with multiple columns of data. I am fine if the data pulls from another sheet I just think there is a better way to do this then filling in 200+ cells with an if:then function based on my selection in cell A1. Anyone know an easy way to do this?
An elegant solution, in my opinion, is to do something like the following:
Create a column (which you can later hide) that has all value combinations, with a delimiter between the values. For example, you could have "Presidents>Barack Obama>Democrat>2008-2016"
Then create a simple function (no VLOOKUP needed!) to pull the individual values by using FIND to findn the location of the delimiters and split the combination.

Google Sheets Formula for Pulling Specific Values in Two Ways

I'm trying to do a couple of different things with a spreadsheet in Google and running into some problems with the formulas I am using. I'm hoping someone might be able to direct me to a better solution or be able to correct the current issue I'm having.
First off all, here is a view of the data on Sheet 1 that I am pulling from:
Example Spreadsheet
The first task I'm trying to accomplish is to create a sheet that lists all of these shift days with the date in one column and the subject ("P: Ben" or S: Nicole") in another column. This sheet would be used to import the data via a CSV into our calendar system each month. I tried doing an Index-Match where it used the date to pull the associated values however I found that I had to keep adjusting the formula offsets in order to capture new information. It doesn't seem like Index-Match works when multiple rows/columns are involved. Is there a better way to pull this information?
The second task I am trying to accomplish is to create a new tab which lists all the dates a specific person is assigned too (that way this tab will update in real time and everyone can just look at their own sheet to see what days they are on-call). However, I run into the same problem here because for each new row I have to change the formula to reflect the correct information otherwise it doesn't pull the correct cell when it finds a match.
I would appreciate any and all information/advice on how to accomplish these tasks with the formula combination I mentioned or suggestions on other formulas to use that I have not been able to find.
Thanks in advance!
Brandon. There are a few ways to attack your tasks, but looking at the structure of your data, I would use curly brackets {} to create arrays. Here is an excerpt of how Google explains arrays in Sheets:
You can also create your own arrays in a formula in your spreadsheet
by using brackets { }. The brackets allow you to group together
values, while you use the following punctuation to determine which
order the values are displayed in:
Commas: Separate columns to help you write a row of data in an array.
For example, ={1, 2} would place the number 1 in the first cell and
the number 2 in the cell to the right in a new column.
Semicolons: Separate rows to help you write a column of data in an array. For
example, ={1; 2} would place the number 1 in the first cell and the
number 2 in the cell below in a new row.
Note: For countries that use
commas as decimal separators (for example €1,00), commas would be
replaced by backslashes () when creating arrays.
You can join multiple ranges into one continuous range using this same
punctuation. For example, to combine values from A1-A10 with the
values from D1-D10, you can use the following formula to create a
range in a continuous column: ={A1:A10; D1:D10}
Knowing that, here's a sample sheet of your data.
First Task:
create a sheet that lists all of these shift days with the date in one
column and the subject ("P: Ben" or S: Nicole") in another column.
To organize dates and subjects into discrete arrays, we'll collect them using curly brackets...
Dates: {A3:G3,A7:G7,A11:G11,A15:G15}
Subjects: {A4:G4,A5:G5,A8:G8,A9:G9,A12:G12,A13:G13,A16:G16,A17:G17}
This actually produces two rows rather than columns, but we'll deal with that in a minute. You'll note that, because there are two subjects per every one date, we need to effectively double each date captured.
Dates: {A3:G3,A3:G3,A7:G7,A7:G7,A11:G11,A11:G11,A15:G15,A15:G15}
Subjects: {A4:G4,A5:G5,A8:G8,A9:G9,A12:G12,A13:G13,A16:G16,A17:G17}
Still with me? If so, all that's left is to (a) turn these two rows into two columns using the TRANSPOSE function, (b) combine our two columns using another pair of curly brackets and a semicolon and (c) add a SORT function to list the dates in chronological order...
=SORT(TRANSPOSE({{A3:G3,A3:G3,A7:G7,A7:G7,A11:G11,A11:G11,A15:G15,A15:G15};{A4:G4,A5:G5,A8:G8,A9:G9,A12:G12,A13:G13,A16:G16,A17:G17}}),1,TRUE)
Second Task:
create a new tab which lists all the dates a specific person is
assigned too (that way this tab will update in real time and everyone
can just look at their own sheet to see what days they are on-call).
Assuming the two-column array we just created lives in A2:B53 on a new sheet called "Shifts," then we can use the FILTER function and SEARCH based on each name. The formula at the top of Ben's sheet would look like this:
=FILTER(Shifts!A2:B53,SEARCH("Ben",Shifts!B2:B53))
Hopefully this helps, but please let me know if I've misinterpreted anything. Cheers.

Filter by multiple values

To explain what I want to do, I will show a much simpler version of my spreadsheet:
I want to be able to filter the Tags to filter column using multiple value of the column Filters available.
For instance, if I select the filters available e and d, I will get back only the lines 15,15 and 17.
My problem is that I don't know how to select the filters that I want and filter the table.
The perfect solution would be to have a list with checkboxes like the one shown in the following picture:
But instead of showing the exact values in this column, it should show the ones in the Filters available table, and after it would filter to show the lines that contains at least one of the options selected...
Do you think I made my question clear?
Try using one extra column with filter condition:
In this sample:
Range A2:A8 = filters available
Range B2:B8 = range where user selects, which filter to use, pasting ones.
Range D2:D9 = tags to filter
Range E2:E9 = extra column with condition
You need only one formula in cell E2:
=ArrayFormula(REGEXMATCH(D2:D9,JOIN("|",FILTER(A2:A8,B2:B8=1))))
ArrayFormula will make it expand down to row 9 automatically. Select your range instead of D2:D9.
REGEXMATCH checks if tags contains selected filters.
JOIN makes string like this: "a|c|e|g" which makes REGEXMATCH to check for any of selected filters: a OR c OR e OR g.
A very easy way of doing this it to use a Pivot Table.
Highlight the data you want to use, then select Pivot Table from the Data menu.
Then Add field to select the Rows and Columns you are after, and include the column you want to filter by in the Filter field
Then you can use the built in Pivot Table Filter to show what you are after.
Giant image showing how to setup and use a pivot table in google sheets
here is a link to the google help for how to create a pivot table:
Link to google help tutorial for how to use pivot tables

Resources