Dynamic Array vlookup formula (Hlookup in a vlookup ??) - google-sheets

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`|

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.

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.

Google Sheet pulling data from another spreadsheet if match

So I'm stuck with something. I have two spreadsheets, column A on each are similar but not identical, some values are on one spreadsheet but not the other.
Is it possible for me to pull data from spreadsheet 2, based on if column A has a matching value?
So spreadsheet 2 will have something like:
A B
item1 100
item2 200
item3 300
and spreadsheet 1 will have something like:
A B
item1 NULL
item2 NULL
item4 NULL
I want to populate the B columns on spreadsheet 1 based on whether they are on spreadsheet 2 (in this instance, it would populate items 1 and 2)
I've tried VLOOKUP and If statements but don't seem to be getting anywhere.
The VLOOKUP function will do this for you, providing that you set the optional is_sorted parameter to FALSE, so that closest matches will not be returned.
Here's an example. First, our source sheet, Sheet1.
On Sheet2, we use VLOOKUP to pull info from Sheet1, using this formula (from B1, in this case):
=vlookup(A1,Sheet1!$A$1:$B,2,false)
^ -------------- ^ ^
| | | +-- is_sorted
| | +------- return value from col 2
| +------------------- Range for search
+------------------------- search_key
Ok, but that #N/A for item4 is not pretty. We can suppress it by wrapping the VLOOKUP in IFERROR. When the optional second argument of IFERROR is omitted, it will return a blank cell if the first argument evaluates to an error:
=IFERROR(vlookup(A1,Sheet1!$A$1:$B,2,false))
In your example, the data is coming from a separate spreadsheet, not just a different sheet within the current spreadsheet. No problem - VLOOKUP can be combined with IMPORTRANGE as its data source.
=IFERROR(vlookup(A1,IMPORTRANGE("<sheet-id>","Sheet1!A1:B"),2,false))
Due to recent changes in Google Sheets, the formula from AdamL and Mogsdad only seems to work when you connect the 2 sheets together.
Remove parts from the formula that don't belong to the importrange..
=IMPORTRANGE("<URL other sheet>";"Sheet1!A2:C")
You get a REF# error but when you hover over the error you can confirm a connection.
I confirmed it works for all cells so you can copy paste the complete formula.
=IFERROR(vlookup(B128;IMPORTRANGE("<URL other sheet>";"SHeet1!A2:C");3;false);)
Following the official documentation you need the complete URL from the other sheet..

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.

Performing lookups with merged cells in Google Spreadsheets

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).

Resources