Performing lookups with merged cells in Google Spreadsheets - google-sheets

Given a set of multi-dimensional data represented in a Google Spreadsheet:
A | 1 | x
A | 2 | y
A | 3 | z
It is pretty straightforward to do a lookup on multiple values using the FILTER and INDEX functions. Doing a lookup for A2 would result in y. However, if the similar data is merged into a single cell:
| 1 | x
A | 2 | y
| 3 | z
Is there a function that would accomplish the same thing? the FILTER method only returns the first row in the implicit set because there is only an A actually on the first row.
If interested, you can view the live sheet here using the 'Rules' sheet.
I have been working on a custom function, but am hoping for something more portable. Helper cells would be fine, as long as I can hide them on a separate sheet.

One option, using the helper cells idea, would be to "normalise" your Rules sheet on a separate (hidden) sheet, and perform lookups on that sheet. Eg, in A3 of that sheet:
=ArrayFormula(HLOOKUP(IF(ROW(Rules!A3:A),Rules!A2),Rules!A2:A,VLOOKUP(ROW(Rules!A3:A),FILTER(ROW(Rules!A3:A),LEN(Rules!A3:A)),1)-1,0))
and fill that formula across to the right as far as required. Note: this formula will only work on the new version of Sheets (which you are using).

Related

Can I filter out pivot table results that only have one row for a value in column A?

I created a pivot table in googlesheets, and it returns results that look like:
first | second | CountOf3
--------------------------
thing | value | 23
| newVal | 3
| cool | 34
that | value | 234
otherThing | cool | 4
| newVal | 345
And I want to filter out results with just one resulting row for the item in the first column.
So in this example, that would be the row: that | value | 234.
I would like the filter to remove that row, and leave the remaining rows. This is a pivot table in a 2nd sheet that updates when Sheet1 changes.
I have been trying all day, and have not been able to come up with a solution. I was hoping there would be some sort of filter, or spreadsheet formula to do this. I've tried multiple combinations of filters, but nothing seems to work - I'm starting to wonder if this is even possible.
It isn't pretty, but a brute force way is to have a check column beside your pivot table, with this formula on the first data row, ie beside "thing | value | 23".
It flags each row where the subsequent cell in column D is not blank. Then use a query (or filter) to list only the output rows you want. Note that you would hide the columns or rows with the actual (unfiltered) pivot output.
This is the simplest version, to see the logic:
=AND(LEN(D3),LEN(D4))
which results in a TRUE value for pivot chart rows that only have one value.
A more elegant version is an arrayformula, adds the header lable, and uses "Skip" as the flag for which rows to filter out.
={"Better Check";ARRAYFORMULA(IF(LEN(D3:D998)*LEN(D4:D999)*LEN(E3:E998),"Skip",))}
Note that this formula allows for a pivot table result effectively to the bottom of the sheet, but it does have a finite range, due to the constraint of checking two rows at once. It could be enhanced by using a COUNTA on the third data column to measure the exact length of the pivot table results and control the range dynamically, Like this:
={"Better Check";
ARRAYFORMULA( IF( LEN(INDIRECT("D3:D" & (COUNTA(F$3:F)+ROW(F$2)))) *
LEN(INDIRECT("D4:D" & (COUNTA(F$3:F)+1+ROW(F$2)))),
"Skip",))}
Let us know if this helps at all.

Dynamic Array vlookup formula (Hlookup in a vlookup ??)

I'm stuck with a complex array vlookup formula.
Explanation:
In one Sheet I have All location worksite
In another sheet, I have all workers.
A simple goal, when a worker has a worksite write in his own line, import other columns via Vlookup. ( Easy )
But I'm trying to do something more: every worker have different type job
I want that the vlookup import a different column for every worker, base on the job type.
So, it's like the return columns have to be different for every worker ... (sound strange)
it's like a vlookup in a vlookup or hlookup in a vlookup?
Any idea how to make this work?
here, a link to the example sheet:
https://docs.google.com/spreadsheets/d/1SY27Hw_Ck24RBJmh5n8hcyt3TrxTm1YPGDKU9DqA7xE/edit?usp=sharing
try:
=ARRAYFORMULA(IFNA(VLOOKUP(A2:A, DB_Localisation!A2:AQ,
MATCH(E2:E, DB_Localisation!1:1, 0), 0)))
spreadsheet demo
Instead of using vlookup the second time it's better to use the combination of Index and Match functions. Like this you can get the offset index you need on the first lookup.
so being this my Sheet2:
+---+----+----+
| | 1 | 2 |
|---|----|----|
| a | aa | bb |
in the first sheet I will have
+---+---+----------------------------------------------------------------+
| a | 2 | `=VLOOKUP(B1,Sheet2!A1:Z100,MATCH(C1,Sheet2!B1:Z1) + 1) //bb`|

Google Sheets Function to get value of adjacent cell based on key

I need some help figuring out some Google Sheets function. I'm trying to look for the value of an adjacent cell based on a key. The problem is that the table has several rows and columns to search for. For example:
| A | B | C | D |
1 | Alpha | 5 | Bravo | 10 |
2 | Charlie | 15 | Delta | 20 |
The list goes on for several more rows and colums. What I'm looking for for example, is when a search use "Delta" as my search key, it will return the value 20 for me. I appreciate your help. Thanks!
Here is the answer I got on the web application community:
https://webapps.stackexchange.com/questions/90198/how-to-get-value-of-adjacent-cell-based-on-key-if-the-table-is-split-into-multi
You can still use vlookup for this, by stacking the lookup tables into one using the array notation {first ; second; third} which means first above second above third. Example:
=vlookup("Delta", {A:B; C:D}, 2, False)
returns 20.
Try:
=offset(lookup("Delta",A1:D2),0,1)
You could use the following:
=ArrayFormula(INDEX($A$1:$D$2,MIN(IF($A$1:$D$2=$G$1,ROW($A$1:$D$2))),MIN(IF($A$1:$D$2=$G$1,COLUMN($A$1:$D$2)))+1))
This could by done in several ways.
Use RegEx
=regexextract(CONCATENATE(A1:D),F6 & "(\d+)")
where F6 is cell with lookup value i.e. "Delta"
Use lookup
=INDEX(A:D,MATCH(LOOKUP(F6,A1:D,A1:A),A1:A),MATCH(F6,INDIRECT(MATCH(LOOKUP(F6,A1:D,A1:A),A1:A)&":"&MATCH(LOOKUP(F6,A1:D,A1:A),A1:A)))+1)
where F6 is cell with lookup value i.e. "Delta", look at example.
MATCH(LOOKUP(F6,A1:D,A1:A),A1:A) is used 3 times, so it could be counted in separate cell.

Display a range of filtered values as a comma-delimited list in one cell on a Google sheet?

Two sheets, one called Core Data, one called Schedule. The Schedule sheet needs to take information about deadlines from Core Data and display it concatenated in deadline-order. (Simple example with numbers and letters instead of dates and tasks given below.)
Here's what I have so far in 'Schedule' (cell B2 specifically in this case):
=JOIN(", ", FILTER('Core Data'!A2:A, 'Core Data'!B2:B=A2))
It's saying no matches are found so I assume this is a problem with the filter component of the formula. However, I've checked the help pages and can't see a problem with the condition I've created.
The formula should:
Get all the values in the given range (cells A2 downward on a 'Core Data' sheet),
Filter them so that only those with certain values are selected. (The information from 'Core Data' should only be selected if the date in the same row on column B matches the date in the cell in the A column on the Schedule sheet.)
Join all these values together and list them as a comma-delimited list.
Example (without dates, for ease):
Core Data sheet:
A | B
-----
a | 5
b | 7
c | 5
d | 3
Schedule sheet (or what it should look like):
A | B
---------
3 | d
5 | a, c
7 | b
Any idea what is going wrong with my formula or if there is an easier way to solve this problem?
The error message I was getting in the cell is:
Error: No matches are found in FILTER evaluation.
It turns out that the cell I was trying this formula on simply had no matches from the filter (no dates corresponded) but instead of returning empty it threw an error. This sounds simple but it's an annoying quirk for me that the cell didn't end up empty which made me assume the formula was at fault.
While the example in the question works you can quickly break it by adding an extra row to the 'Schedule' table with "8" as the value in the A column and the formula in B:
A | B
---------
3 | d
5 | a, c
7 | b
8 | N/A
The "8" throws an error since it isn't found in the 'Core Data'.
Conversely, on my original spreadsheet, When I tried the formula in a cell which did correspond to a noted deadline, it worked.
I found the solution here is to add an IFERROR function to the formula to deal with this.
So a formula that works for this is:
=JOIN(", ", IFERROR(FILTER('Core Data'!A:A, 'Core Data'!B:B=A5)))
One does not use the second IFERROR argument as advised in Google's own helpsheet. I tried putting in an empty array at first ({}) but this threw a different error. It seems if you miss the argument out, the JOIN knows it has nothing to work with and the cell ends up with a nice blank value.

Is there a multiple-and-add formula in Google's spreadsheet?

What I want is to easily multiply a number by another number for each column and add them up at the end in Google Sheets. For example:
User | Points 1 | Points 2 | Points 3 | Total
| 5 | 1 | 4 |
-----+----------+----------+----------+------
Jane | 2 | 3 | 0 | 13 (2*5 + 3*1 + 0*4)
John | 1 | 11 | 4 | 32 (1*5 + 11*1 + 4*4)
So it's easy enough to make this formula for the total:
= B3*$B$2 + C3*$C$2 + D3*$D$2
The problem is I frequently need to insert additional columns or even remove some columns. So then I have to mess with all the formulas. It's a pain... we have many spreadsheets with these formulas. I wish there was a formula like SUM(B3:D3) where I could just specify a range. Is there anything like MULTIPLY_AND_SUM(B2:D2, B3:D3) that would do this? Then I could insert columns in the middle and the range would still work.
There is a built in function in Google Sheets that does exactly what you are looking for: SUMPRODUCT.
In your example the formula would be:
=sumproduct(B$2:D$2,B3:D3)
Click here for more information about this function.
You can accomplish that without requiring a special-purpose function.
In E3, try this (and copy it to the rest of your rows):
=sum(arrayformula(B3:D3*B$2:D$2))
You can read about arrayformula here.
As long as you introduce new columns between B and D, this formula will automatically adjust. If you add new columns outside of that range, you'll need to edit (and cut & paste).
On it's own, arrayformula(B3:D3*B$2:D$2) operates over each value in B3:D3 in turn, multiplying it by the corresponding value in B$2:D$2. (Note the use of absolute references to 'lock down' to row 2.) The result in this case is three values, [10,3,0], arranged horizontally in three rows because that matches the dimensions of the ranges.
The enveloping sum() function adds up the values of the array produced by arrayformula, which is 13 in this case.
As you copy that formula to other rows, the relative range references get updated for the new row.

Resources