Google Sheets: Conduct VLOOKUP on array stored in a different cell - arrays

I am trying to store a series of key/value pairs in a single cell in Google Sheets, then interrogate the array using formulae, such as VLOOKUP().
As an example, there is an array storing a series of key/value pairs: ​
{"keyA", "valueA"; "keyB", "valueB"; "keyC", "valueC"}
You can use VLOOKUP on this array if it is embedded in the formula:
=VLOOKUP("keyB",{"keyA","valueA";"keyB","valueB";"keyC","valueC"},2,FALSE)
which will return "valueB".
But if you store the array in a cell (eg B2) and refer to that cell in the formula, eg:
=VLOOKUP("keyB",B2,2,FALSE)
...you get a #REF! response with the detail: "Error. VLOOKUP evaluates to an out-of-bounds range."
Can anyone suggest a solution to this please?
Many thanks

There is no EVALUATE formula in Spreadsheet.
The array expression is some kind of formula, in order to output a range of values, you have to put:
={"keyA", "valueA"; "keyB", "valueB"; "keyC", "valueC"}
You could then do VLOOKUP on the output.
However, you can parse it yourself with SPLIT
=ArrayFormula(SPLIT(TRANSPOSE(SPLIT(REGEXREPLACE(B2,"^{""|""}$",),"""; """,FALSE)),""", """,FALSE))

Related

Google Sheets Array Function that returns a specified location of the array in one cell

I'm trying to create a google sheets function where I use a array function [like UNIQUE() or FILTER()]but the array is returned into one cell and I can specify the location of the value I'm trying to obtain.
I think its analogous to a List in R where you have a list full of a number of string characters and you can return the one you want by specifying where it falls in the list.
Below is a sample of the problem I'm trying to solve.
Functions are as follows:
In cell B1: =UNIQUE(A1:A12)
In cell E1: =CHOOSE(C1, $B$1, $B$2, $B$3, $B$4)
I'd like all of this to happen in one cell. Is that possible? I was thinking maybe Lambda functions would be helpful here but I couldn't understand it well enough to use it in this scenario.
I have tried without success a bunch of combinations of the following functions: Lambda functions, Index(), Choose()
Thanks a ton!
I'm not sure why you're having trouble with INDEX in this situation. Given the list in A1:A12, =INDEX(UNIQUE(A1:A12),n) where n is 1-4 will give you the item at that position in the array?
For multiple ns use MAP to supply the row values to INDEX:
=map({n1;n2...},lambda(n,index(unique(A1:A12),n)))
Try put this into E1 in your sample sheet.
This formula do exactly what you have requested.
Pack all your formulas (UNIQUE(A1:A),CHOOSE(C1)) up into one cell with the help of LAMBDA and INDEX.
The output will change according to the numbers you enter in C1:C4.
=LAMBDA(ARRAY,INDEXES,
LAMBDA(VAL_1,VAL_2,VAL_3,VAL_4,
BYROW(INDEXES,LAMBDA(ROW,
CHOOSE(ROW,VAL_1,VAL_2,VAL_3,VAL_4)
))
)(INDEX(ARRAY,1),INDEX(ARRAY,2),INDEX(ARRAY,3),INDEX(ARRAY,4))
)(UNIQUE(A1:A),$C$1:$C$4)

Fill Empty Cells With The Same Value as Previous Cell in Google Sheet (Array Formula)

I have a list of data that can be seen in this example:
https://docs.google.com/spreadsheets/d/1bRiupsmjfDRE9AgcM_5KJKAyxYKpQiMuyAGSoGaZYN0/edit?usp=sharing
Range A:B is the given data
Range D:E is the desired result
It is very easy to solve it without array formula. But Is there any array formula that can work it out? I need array formula so that i dont have to drag again and again when the data is added below.
use:
=INDEX({A:A, IF(A:A="",, VLOOKUP(ROW(B:B),
IF(B:B<>"", {ROW(B:B), B:B}), 2))})
For column B, put in C1
=ArrayFormula(lookup(row(B:B),row(B:B)/if(B:B<>"",1,0),B:B))

Find Range of Excel Array Formula

A certain cell is part of a range containing an array formula (created using CTRL-SHIFT-ENTER). Other than my brute force method of visually examining the formula in the certain cell, does Excel have a command that will highlight the range of cells which contain the array formula? For instance, assume C10 has the following array formula ={TRANSPOSE(myarray)}, how can I ask Excel to highlight the range of cells that will receive the contents of the transposed "myarray"?
This feels like a Excel 101 question but my search has been futile.
If there is no "junk" below the array formula, something like:
=COUNTA(C10:C9999)

Excel formula: counting array elements with a criteria

I have an array, which is the result of the multiplication of two COUNTIF functions.
The result is {0,2,7,4,0}. I want to count the number of non-zero elements. I tried the following:
=COUNTIF(COUNTIF*COUNTIF,">0") <- here the two inner COUNTIFs are short for the complete formula
It did not work. I then tried the following, which did not work either.
=COUNTIF({0,2,7,4,0},">0")
I resorted to using the following array formula and it worked.
{=SUM(IF(COUNTIF*COUNTIF>0,1,0))}
Two questions:
does COUNTIF only accept cell reference but not constant array?
any solution other than array formula?
Thanks.
The first argument of COUNTIF must be a range, nothing else will do.
You can just enter this as an ordinary formula:
=SUM(--({0,2,7,4,0}>0))
However when the array comes from a calculation, you need to coerce it to process all the elements either
=SUM(INDEX(--(A1:A5>0),0))
or like #Jeeped with Sumproduct
=SUMPRODUCT(--(A1:A5>0))

Google Sheets Dynamic Range (for finding instance number) Countif in arrayFormula

I find the instance number of a data entry by using:
=countif(C$2:C2,C2)
When filled down, this formula displays the number of times C2,C3,C4,etc. occurs above it, thus giving its "instance number".
I would like to convert this to an array formula (to avoid the need to fill down) but,
=arrayformula(countif(C$2:C2,C2:C))
does not work. I am unsure how to convert the range argument of countif to comply with the arrayformula while keeping this range dynamic.
Example sheet:
https://docs.google.com/spreadsheets/d/1cApbO2HdeiaJd7yEkS1oFzxEG5wuM2XHLU7CK_OqRCA/edit#gid=0
Adapted a solution from here which ultimately had an unknown source.
=ArrayFormula(if(len(A2:A),index(sort(iferror({sort(row(A2:A),A2:A,1),row(A2:A)-row()+2-vlookup(sort(A2:A),{unique(A2:A),iferror(match(unique(A2:A),sort(A2:A),0))},2,0)})),,2),))
A simple way to countif with arrayformula:
=ArrayFormula(COUNTIF(A1:A6,A1:A6))
Tip: use the same range twice

Resources