Is it possible to use an array within a Google Sheets function - google-sheets

Is it possible to have an array within a formula, as opposed to referencing the array in cells.
For example with VLOOKUP, I have tried to do this but it doesn't work:
=VLOOKUP(I2,[["Superking",4],["King",3],["Double",2],["Single",1]],2,0)
I'm essentially trying to incorporate the below table into the formula itself:
Superking 4
-----------------------------
King 3
-----------------------------
Double 2
-----------------------------
Single 1
I thought that this is maybe possisble but expressing the array incorrectly.
I do know that this can easily be done by putting the actual data into the sheet, but I am interested to know if it is posisble to do it this way.

This seems to work:
=vlookup("Pete", {{"John",9};{"Pete", 2}}, 2, false)

Yeah, this is the format to do it.
={"one","two","three","four","five";1,2,3,4,5}
will produce

Related

How to check multiple ranges for different values in Google Sheets

I'm trying to search 3 different ranges in a tab, and trying to display Yes if all three values (email address, name, x) are found in those ranges. Basically, trying to have the formula confirm that yes, all three of those inputs are somewhere in those ranges (order doesn't matter).
Maybe I should use query or regexmatch or something? Any help is appreciated
Tried this formula:
=IF(AND('Helper Calculations'!$I:$I=$A$1,'Helper Calculations'!$J:$J=L$1,'Helper Calculations'!$L:$L=$A2),"Yes","No")
Was expecting that if the search term in each of those cells ($A$1, L$1, $A2) is found somewhere in the corresponding ranges, then it would say Yes
You can try with this (you can change the use of asterisks by wrapping in AND:
=IF(COUNTIF('Helper Calculations'!$I:$I,$A$1)*COUNTIF('Helper Calculations'!$J:$J,L$1)*COUNTIF('Helper Calculations'!$L:$L=$A2),"YES,"NO")
try:
=INDEX(IF(('Helper Calculations'!I:I=A1)*
('Helper Calculations'!J:J=L1)*
('Helper Calculations'!L:L=A2), "Yes", "No"))
Took a bit more work than I expected, but I got this working. I needed to verify that all 3 values were correct in a single row (must all be correct on that one row, can't find the correct values on multiple rows).
In order to do that, I needed to use array formula, and then decided to use index match and concatenate for the 3 values.
Process described here: https://www.ablebits.com/office-addins-blog/google-sheets-index-match/
correct formula: =IF(ArrayFormula(INDEX('Helper Calculations'!$I:$I,MATCH(CONCATENATE($A$1,L$1,$A2),'Helper Calculations'!$I:$I&'Helper Calculations'!$J:$J&'Helper Calculations'!$L:$L, 0),))=$A$1,"Y"))

Arrayformula - Adding together a dynamically generated list of ranges

I'm looking for a way to add together a dynamically generated list of ranges using (I'm guessing) an ARRAYFORMULA.
The normal way of attacking this is fine if there is a known list of ranges, the example of the results I want would work using this:
=ARRAYFORMULA( A1:A10 + B1:B10 )
In the case I'm after I want to add together ranges in multiple sheets. I don't want the users to have to manually adjust the array formula every time they add a new sheet to be calculated, and I also want to be able to add some logic to include or remove the particular sheet from the calculation, but for now I'm happy to ignore that and just focus on adding cells together.
My approach to this was to create a column with a list of names, each one matching a sheet in the document, and then using that list to dynamically build the list of ranges to add together, using INDIRECT.
.------------.
| sheet1 | <---- SheetListNamedRange
|------------|
| sheet2 |
`------------'
Here's a quick example
=ARRAYFORMULA( INDIRECT("'" & SheetListNamedRange & "'!D4:75") )
There are lots of failure modes depending on how it's done, but this particular formula only puts in the values of the first sheet and ignores any others, which I guess makes sense.
What I'm after is kind of the equivalent of i++ in a loop found in a normal coding language. Is there some way of making this work?
If I understand you correctly, you'd like to get a list generated based on different ranges across different sheets. If your case is as simple as the one you mention in the beginning of your post, the following would do the job.
={Sheet1!A1:A2; Sheet2!B1:B2}
If you want the sum of all these values, you can use SUM.
=SUM({Sheet1!A1:A2; Sheet2!B1:B2})
Please let me know if this isn't what you were looking for, so I can change the answer accordingly.
you can't refer to array of arrays in INDIRECT. you will need to INDIRECT each sheet which contains array.
=SUMPRODUCT(ARRAYFORMULA(INDIRECT(A1&"!"&"D:D")+
INDIRECT(A2&"!"&"D:D")+
INDIRECT(A3&"!"&"D:D")+
INDIRECT(A4&"!"&"D:D")))
note1: in this case result is 25 as sum of 10 + 15.
10 is sum of sheet1!D:D
and 15 is sum of sheet2!D:D
note2: there is no sheet3 and sheet4 which is equal to 0 in INDIRECT
note3: D:D of the sheet where you have the list of sheets needs to be empty

Convert columns to rows in Google Sheets

I have a spreadsheet that looks like this
A B C D E
-------------------------------------------------------------------------
Mercedes A Class C Class E Class G Wagon
BMW 1 Series 3 Series 4 Series
and I wish to create a spreadsheet that looks like this
A B
------------------------------
Merecedes A class
Merecedes C class
Merecedes E class
Merecedes G Wagon
BMW 1 Series
BMW 3 Series
BMW 4 Series
I have used the transpose function, but it doesn't create a new record for each value, but rather just rearranges the columns.
How might I achieve this?
I have been looking for this same answer.
What you are trying to do it called unpivoting but it doesn't look like there is a built in function in google sheets to do it.
I found this fix in the google product forums. https://productforums.google.com/forum/#!topic/docs/5UAxnQKMFm8
At first glance it looks a little complicated but victor tabori's code worked like a charm.
copy and paste his code into tools script editor in your google sheet and then use the =unpivot function in your spreadsheet. Only limitation I ran into was it failed trying to reference data in a different page of the sheet.
For the sake of anyone who's search brought them to this old question on this perennial need; this type of rearranging is a bit easier than it used to be, with Google's addition of the FLATTEN function. Example formula:
=ARRAYFORMULA(QUERY(SPLIT(FLATTEN(A2:A&"|"&B2:E),"|"),"select * where Col2 is not null"))
From the inside out, here we work on a temporary array of makes and models,
with a symbol | concatenated between makes from A and models found in B:E,
FLATTEN then puts it all into a single column,
then SPLIT uses the temporary | characters to split it to a two-column array,
and finally, a quick QUERY lets us filter out blanks after the fact (like the row E3 would become), without having to do all the calculations twice.
Oh, and ARRAYFORMULA lets it work across the whole array of makes and models we input.

How to make a relative reference in an array formula in Google Sheets

Here's the straightforward version of my question:
I want to change the following formula to an array formula...
Original formula (from cell J2):
=if(F4="VM:",G4,J1)
My attempt at converting to an array formula (in cell K1):
=arrayformula(if(row(A:A)=1,G3,if(F:F = "VM:",G:G,indirect("K"&row(A:A)-1))))
This works on rows where F = "VM:", but returns a #REF error on other rows. Function INDIRECT parameter 1 value is 'K0'. It is not a valid cell/range reference.
Thoughts on how to fix this?
The more complex version of my question. i.e. Why am I trying to do this?...
I have a weird spreadsheet with data that should really be in a Wiki.
I want to create filter views for each person so they can easily filter on only their own vendors. The original formula will work, but as more vendors are added, I'd like for the formula to automatically work for those rows as well.
If there's a better way to do this, I'm listening.
I don't exactly understand your needs, but If you want to autopopulate your formula, then you only need this code in desire column in row 4 (you can change this to any other - this will autofill down from this point):
=ArrayFormula(if(F4:F="VM:",G4:G,J1:J))
Is this what you are trying to get?
After clarification:
You need this code in J2 only:
=ArrayFormula(VLOOKUP(ROW(J2:J),
QUERY({F:G,ROW(G:G)},"select Col3,Col2 where Col1='VM:'",1)
,2,1)
)
Works for you?
maybe you just need to hide errors?
=IFERROR(ARRAYFORMULA(IF(ROW(A:A)=1,G3,IF(F:F = "VM:",G:G,INDIRECT("K"&ROW(A:A)-1)))),)

Google spreadsheet, passing parameter

Okay, I'm an huge noob with that kind of stuff, and I don't really know where to begin with. Google help is somehow not enough :/.
I want to make a conditionnal count on a single column :
COUNTIF(A1:A10, "3")
It will return the number of 3 in the cells from A1 to A10. Now the problem is, there can be multiples values in each cell formatted like this : "1; 3; 5". I can easily match this using regex :
B1 = REGEXEXTRACT(A1,"3")
Then repeat and sum on the second column. Now, how can I do this using a single formula?
COUNTIF(A1:A10, REGEXEXTRACT(A1:A10,"3"))
This doesn't work because regexextract take as an input a single cell. I would like to tell it to use the same cell than in the countif, but I have no clue on how to achieve this.
you can have regextract working on an array. E.g.:
=ArrayFormula(sum(--regexmatch(A2:A&"", "3")))
should count all threes (either single or in cells with multiple values), but in case you have multiple threes in one cell, you may need to use something like this:
=ARRAYFORMULA(sum(len(A:A)-len(SUBSTITUTE(A:A,"3","")))/len("3"))
This should work:
=COUNTIF(SPLIT(JOIN(";",A:A),";"),"3")

Resources