How to get only the Surname in a range of cells? - google-sheets

I have a spreadsheet having a column of names. Now, in another sheet I want to have the surnames from the aforementioned column to be displayed in a dropdown. How can I do this?
The names look like this:
Surname, FirstName
And there are also people from the same household having the same surnames. There are no people with the same surname that belong to different households. So I kind of want to get the surnames to identify that household.

You can create a single array formula referencing that list of names, that only pulls the surname portion using regexextract like this:
=IFERROR(UNIQUE(ARRAYFORMULA(REGEXEXTRACT(A:A,"^(.*),"))))
To explain, the regexextract, I feel is a lighter formula and slightly simpler than using a split function for two reasons:
A split function would require you put both names to two separate cells, and unfortunately split function does not work with arrayformula.
But since regex does - the regex I specified is basically saying grab any text (.*) from the beginning of the cell ^ up until that comma ,.
I then wrap the whole function in unique, so you dont have to deal with a ton of duplicates in your dropdown.
Following that I used Data Validation to point to the range of these unique surnames.
And just for fun at the end I finalized it with a FILTER function that would populate all the corresponding cells based on the surname chosen from the dropdown using this formula:
=FILTER(A:A,REGEXMATCH(A:A,C1)=TRUE)
To wrap all this information up, here is a sample image of what it looks like in the end:

I guess you have to split the names into another column. Let's say your names column is in A1, set the following formula in B1 and copy it in the next cells of the B row :
=SPLIT(A1;",")
Then, you can define your dropdown list in another sheet as explained here : https://support.google.com/docs/answer/186103

Related

Google Sheets filter() wrapped in arrayformula() without vlookup()

Reference/test sheet: https://docs.google.com/spreadsheets/d/1fp6ZTBtgb5E0J9GKOqh8Ae47OzY1smec5ha9BfUfAsY/edit?usp=sharing
I have a Google Sheets document with one sheet (calculator) that pulls some values from another sheet (database). database is organized by two columns: make, and model. I use some weird data validation and helper columns to make dropdowns in calculator. Then I use filter() to pull the matching value from database.
This all works fine but it will be a calculator that gets reused and the data discarded, so I need only a finite number of rows in calculator (10-20). For this, it would be super nice to be able to select the whole row and hit delete to clear the calculation without destroying all the formulas. Ideally, the filter() would happen inside an arrayformula() in a hidden and protected top row to allow the rows to be easily cleared.
For some reason though, I can't get that to work. vlookup() is not an option because I need to match two keys.
On another note, it would be nice to not need the helper columns B:J and the data validation unique to each row. This is workable though as I only need a few rows. In the actual version I hide and protect B:J and there are many more columns there.
I know you said Vlookup() wouldn't work because you need to match on two keys, I think that vlookup() will help in this situation. Try this formula...
=arrayformula(Vlookup(A3:A&K3:K,{database!A$2:A&database!B$2:B,database!C$2:C},2,False))
The concept here is to put those two matches you need into one unique key. So we use the curly brackets {} to build an array within the formula and combine those two lookup fields in your 'database' sheet. So the columns of A and B become concatenated into one element, and the second part of that array is the column C which you need.
To lookup then just combines your A&K columns similarly, so it can lookup that combined element. The rest of the vlookup follows as normal. I.e. we look up this concatenation against that one and when it matches it returns the second column of the array we built, in this case database!C.
I don't think I'm clear on your columns B:J, so I'm not sure if this helps you with that as well.
You can't get rid of the helper column approach, as long as you want the calculator to use drop down selection for the model. Data validation for dropdowns requires either a list of values, ie. static, so no good, or a range of cells.
What you might want to do is to put those cells in a totally separate tab, eg. DataValidation, and then hide that tab. Your Calculator sheet will then be cleaner, with no hidden columns. Column K will use for data validation the "hidden" values, formerly columns B:J, that are now built off in the DataValidation tab.

Google Spreadsheets complex look up

I have three columns like so:
Column 1 is a numeric identifier essentially just the row number
Column 2 is a country name
Column 3 is a comma separate string of country ids, may be blank (represents a relation between the country for that row and the other countries in the comma separated list).
What I want is to put a comma separated list of countries in column 4 which is more readable than the ids. Pretty much a code table look up but complicated because it is not a single value in the cell but a collection of values. I don't own the table so I can't change the way the data is coming to me from the source - I can do whatever I want with it once I get it though :)
I could also live with breaking out the comma separate values into separate columns, so long as the new columns contain the country names and not the ids.
As requested here is a link:
https://docs.google.com/spreadsheets/d/1LY_8xh992pjZnoNSP-7P5x2iD1VVFozy8stlH4DLqNQ/edit?usp=sharing
You can use following formula:
=TEXTJOIN(",",TRUE,FILTER($B$2:$B,SEARCH(","&$A$2:$A&",",","&C2&",")))

Searching for any of the words in a cell from another cell

So I have a question: Let's say I have 3 columns: Artists, Tracks, Sublabel in 2 sheets.
Here's the example sheet
What I need is a function that searches for the value in the cell "tracks" in Sheet2 from Sheet1,
Once find the value we are looking for, I want it to check for any words that the cell "Artists" in sheet2 may match the words in the cell "Artists" from sheet1, if one of the words is a match then go ahead and get the value from cell "sublabel" in sheet1 to write in cell "sublabel" in sheet2.
(We do not wanna check for the exact string as the one in sheet2 as they may be slightly different having words in a different order and some missing, but usually they are separated either by a comma, fullstop, space or a short word like "ft.". "Tracks" cells will always have the same values/strings in both sheet tabs, but the "Tracks" may be by a different "Artist" that being why the "Artists" cell must contain at least one of the words from the other sheet.)
I've tried to use the following function but it's not doing exactly what we need though as we need a way to check if artist is correct but can't use exactly the same values to search:
=dget(Sheet1!A:C,"Sublabel",{"Artist","Track";A7:B7})
Hope someone can help us! Thanks!
I can't get the exact result you want, a table filled in as you proposed.
But the following might be useful depending on what you want to do with the data.
This provides a dynamic listing of your data, where you can select a track title, or part of a title, and any part of an artist's name, to filter the results.
I added a sample tab to your sheet: Sheet2-GK. The formula, which is build dynamically, based on the filter values you select, looks something like this (sample criteria being used):
=QUERY(Sheet1!A2:C19,
"select * where A contains 'Sam' and A contains 'Kygo'
and upper(B) contains 'GIVE' order by A,B",0)}
It could be enhanced, to permit "AND/OR" selection of two artists' "names" for example. "Names" here refers to any one word found in the Artist field. Eg. Diana Ross would show as two unique names, "Diana" and "Ross".
Let me know if this is helpful, or if you really need that initial full report you described in your question.

Google Query on the results from unique function

I am using google sheets and applied a UNIQUE function on a set of columns and want to apply a query function to take couple of columns and all rows from the the results to a different sheet, but I am getting blanks.
Can you please suggest what am I doing wrong?
Does the Query function not work on the results from UNIQUE function?
Open or create a sheet.
Select a cell.
Type = followed by the sheet name, an exclamation point (!), and the cell being copied.
For example, =Sheet1!A1 or ='Sheet number two'!B4.
Note: If a sheet name contains spaces or other non-alphanumeric symbols, include single quotes around it (as in the second example).

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.

Resources