Get multiple values, selected according to another column, into a single cell - google-sheets

I am trying to find a way to get multiple values from an array to display in one cell
For example I have the two columns as below
| a | 1 |
| b | 2 |
| c | 1 |
| d | 3 |
| e | 2 |
So if the parameter is 2 the cell would display "be"
I want all the values form the first column where the second column is 1.
I have tried to do this with dget but that only returns a single value. Is there a way to do this with formulas or does it require a Javascript solution?

You can do it by using filter to return only the letters next to "2", and then join to join them in one cell.
=join("", filter(A1:A, B1:B = 2))

Related

Convert a list of rownumbers to a list of cells and apply a formula to them in Google Sheets

I have a list of numbers in Column B corresponding to different rownumbers in Column A (for example, in B1, I have the list {1,2,3}).
I would like to turn this list into a list of cells ({A1,A2,A3}) and apply a formula to that list in Column C (for example, I would like to AND them together).
Column A always contains Boolean Values.
Column B will always contain valid rownumbers separated by a comma.
I would like a formula that I can put in Column C and drag down and extract the numbers from (for example using =SPLIT(B1,",")) and then apply a formula to.
Shown in the table below is a sample of what I would like to achieve. Note that Column C contains a manual entry approach that I would like to avoid.
| Column A | Column B | Column C | Column D (expected ouput)
| -------- | -------- | -------------- | -----------
Row 1 | TRUE | 1,2,3 | =AND(A1,A2,A3) | FALSE
Row 2 | FALSE | 2,4 | | FALSE
Row 3 | FALSE | 4,6,2,1 | | FALSE
Row 4 | FALSE | 2 | | FALSE
Row 5 | TRUE | 1,5 | | TRUE
Row 6 | FALSE | 1,5,3 | | FALSE
Some things I have tried include using
=INDEX(A:A,SPLIT(B1,","),1)
=AND(ARRAYFORMULA(INDEX(A:A,SPLIT(B1,","),1)))
I have also tried moving around the order of the formulas in the above equation to no avail.
I have only managed to get my formula to be affected by the first rownumber in column B.
You were very close! With BYCOL (considering that the SPLIT result is a serie of cells in columns) you can get the INDEX of column A; and wrap it in AND:
=AND(BYCOL(SPLIT(B1,","),LAMBDA(i,INDEX(A:A,i))
If you want, you can wrap it in BYROW to apply to your whole range:
=BYROW(B:B,LAMBDA(b,IF(b="","",AND(BYCOL(SPLIT(b,","),LAMBDA(i,INDEX(A:A,i)))))))

Count unique cells and display them in column

I am building a list of gigs I attended and I want to count how many times I've seen each band.
I know about UNIQUE, but because I keep each band in separate column it just copies each row.
Given the table (or screenshot of real data):
| Date | Venue | Bands |
|----------|--------|--------|--------|--------|--------|--------|
| 02.02.17 | Venue1 | Band A | Band B | Band C | Band D | Band E |
| 02.07.17 | Venue3 | Band D | Band C | | | |
The output I want:
| Band | Attended |
| | (times) |
|--------|----------|
| Band A | 1 |
| Band B | 1 |
| Band C | 2 |
| Band D | 2 |
| Band E | 1 |
I can change structure if needed.
What happens after using UNIQUE: https://i.stack.imgur.com/qmszk.png
Thanks in advance.
Step 1. Get list of all unique bands in one column, one per row
=ArrayFormula(UNIQUE(TRANSPOSE(SPLIT(CONCATENATE(Gigs!D2:Z&CHAR(9)); CHAR(9)))))
Step 2. Place this formula in next column, and drag it down
=SUM(COUNTIF(Gigs!D:Z; E2))
Transform your data to a simple table format in order to make easier to do data-analysis.
A simple table use the first row for column headers a.k.a. fields and has one and only one column for each entity, let say only one column for band names.
The above could be done in a single but complex formula hard to debug, so it's better to start by doing this using simple formulas and once you are certain that all is working fine, think about making a complex formula or writing and script.
Related
Unpivot Matrix to Tabular. Using counts of two variables into individual rows
Generate a list of all unique values of a multi-column range and give the values a rating according to how many times they appear in the last X cols
Normalize (reformat) cross-tab data for Tableau without using Excel
How do you create a "reverse pivot" in Google Sheets?

Conditionally formatting duplicate rows in google sheets

I want to apply conditional formatting so that all the rows which match another row exactly are highlighted.
Let's say I have a spreadsheet like the following
| | a | b | c |
|---|---|---|---|
| 1 | A | B | C | // Matches row 3 and 6
| 2 | A | B | A | // Matches row 5
| 3 | A | B | C | // Matches row 1 and 6
| 4 | B | B | C | // Matches no other row
| 5 | A | B | A | // Matches Row 2
| 6 | A | B | C | // Matches row 1 and 3
| 7 | B | B | A | // Matches no other row
All the rows except for row 4 and 7 would be highlighted.
For to rows to be considered duplicates, the value of each/every cell in a given row must exactly match the value of the corresponding cell (cell in the same column) in a duplicate row.
My attempt so far can only return the values of rows with only the first 2 cells being duplicate and returns the concatenation of all the duplicate values in each row, which is very far away from what I want.
CC = arrayformula(A:A&" "&B:B&" "&C:C) returns a new row which is the concatenation of A, B, and C, which is coercing the cell values into strings so "1" and 1 which are not the same appear to be the same, and also doesn't work across the entire row (could do If I just kept adding Columns, but would look terrible).
=filter(unique(CC), arrayformula(countif(CC, unique(CC)) > 1)) CC is the returned value from the previous equation
This would output
A B C
A B A
Then I could add a conditional formatting rule with a custom formula that Highlights a row if it's concatenated contents "Match" one of the return values from the previous equation, but I don't know how to do that, and the previous equation is already pretty flawed.
Ideally I want a solution that involves no string concatenation or entering in all column names.
Let's go over what is needed to create this function.
1st you need to get the rows as a string to be able to compare them like you did. I didn't use space like you did because it takes place, but you can keep them.
=ARRAYFORMULA(A:A&B:B&C:C)
The issue with that is that since the formula will be on 3 column, we don't want it to become C:C&D:D&E:E so we have to fix the column.
=ARRAYFORMULA($A:$A&$B:$B&$C:$C)
Yay! Now we have a list of string that represent the "value" of each row. We can now count for each line how many times they are found. I used A2 cause I guess you have a header, but if you don't, simply replace it with A1.
=COUNTIF(ARRAYFORMULA($A:$A&$B:$B&$C:$C);A2&B2&C2)
We also have to fix the column here or the function will only work on the 1st one.
=COUNTIF(ARRAYFORMULA($A:$A&$B:$B&$C:$C);$A2&$B2&$C2)
And now all that's left is check if you want to see thoses who are unique or thoses who have matches
=COUNTIF(ARRAYFORMULA($A:$A&$B:$B&$C:$C);$A2&$B2&$C2)>1
This solution doesn't involved converting the values to strings, but it still requires adding a function for every column, so it's almost there.
=countifs(arrayformula($A:$A=$A1),TRUE,arrayformula($B:$B=$B1),TRUE,arrayformula($C:$C=$C1),TRUE)>1
It's just a conditional for each column conditional = arrayformula($A:$A=$A1) in a countifs, countifs(conditional, true).
I just need to make it so it can take the column values as an array which i'm guessing will require an arrayformula
There is a MUCH simpler way.
Load Conditional Formatting (under Format).
Select "custom formula is" (way at the bottom of the formula list)
Use the formula "=countif(A:A,A1)>1", where A is the column that contains the cells you want to be formatted for duplicates.

Structuring a query between multiple tabs to join values by name

I'm trying to write a SQL query in Google Sheets to try and get data for "matching" results from two different tabs, but running into some trouble.
This is a sheet that's basically an automated scoring engine for instructors who take a two-part test (written and practical). After the results are entered, I'd like to use some SQL to take the results from the two tabs and collate them into a final score.
Link to the sheet in question.
There's a "Practical Scores" tab (which takes all the data from the associated Google Form), and a "Written Scores" tab. I'd like to get the name of the instructors who match in both those tabs, and give the associated score for them, but I'm mostly having trouble with writing the correct SQL.
Most of what I'm trying to do is working fine. I'm able to pull the final practical scores via the following SQL:
=query(PracticalScores!A2:E, "select A, count(E),SUM(E)/3 group by A")
I can also pull the written scores as follows:
=query('Written Scores'!B2:C,"select B,C")
But I want the intersection of the two as well, and that's where I'm running into problems.
=query(A8:E, "select A,C,D where A = E")
will simply return the rows where the names match up, and I want the instances where the names match up, regardless of whether the rows do.
That is, I want all the rows where the names match from tab 1 to tab 2 and not just the few rows that happen to line up perfectly.
If I'm not explaining this well, please let me know and I can provide additional information. Any assistance would be very greatly appreciated!
Since the query function does not support joins, this can't all be done in one query. Instead, the following device can be used:
=arrayformula(vlookup(name column, table, # of column to extract, False))
For example, suppose I have a table
+---+-------+---+
| | A | B |
+---+-------+---+
| 2 | Jim | 3 |
| 3 | Sarah | 4 |
| 4 | Bob | 5 |
+---+-------+---+
to which I want to add another column, taking it from
+---+-------+---+
| | E | F |
+---+-------+---+
| 2 | Sarah | 9 |
| 3 | Bob | 8 |
| 4 | Jim | 7 |
+---+-------+---+
The basic idea is to put in cell C2 the formula
=arrayformula(vlookup(A2:A, E2:F, 2, false))
which will look up every name from first table (column A) in the column E, and return the matching value in column F. Result:
+---+-------+---+---+
| | A | B | C |
+---+-------+---+---+
| 2 | Jim | 3 | 7 |
| 3 | Sarah | 4 | 9 |
| 4 | Bob | 5 | 8 |
+---+-------+---+---+
In practice, one should filter out empty lookup values to improve performance:
=arrayformula(vlookup(filter(A2:A, len(A2:A)), E2:F, 2, false))
If the second table contains some names not present in the first, they will not be returned by the above formula. In this case it is better to prepare a full list of names, for example with
=sort(unique({Sheet1!A2:A; Sheet2!A2:A}))
which collects the names from A columns of two sheets, eliminating duplicates and sorting. Then look up those using vlookup as above.

Search for a particular cell in Google Spreadsheets and return the row number

For instance, I have a bunch of categories with 1 on each row and each category has 1 or more data on their own column. Given a string, I want to find which category it belongs to.
A | B | C | D
1 CARS | Civic | |
2 TRUCKS | F-150 | F-650 | F-750
3 PLANES | 747 | F/A-18 |
Given 747, I want to know that it is from row 3 or that it is a plane or that F- is a truck.
I've tried using several functions, including vlookup, filter, match, etc, but couldn't get them to work.
Is it possible to do this without scripts?
Assuming the data is in columns A to E (this could be extended), and that the search term is in F1, and the search term must start the string, and that all applicable matches will be returned, try:
=IF(LEN(F1),FILTER(A:A,COUNTIF(IF(REGEXMATCH(B:E&"","^"&F1),ROW(A:A)),ROW(A:A))),)

Resources