How to reference a different spreadsheet in HLOOKUP? - google-sheets

I try to reference another spreadsheet in the HLOOKUP formula but fail. I'm doing this like:
=HLOOKUP(A2,"https://docs.google.com/spreadsheets/d/1qOzV/","report!A2:B2",2,0)
where http... is the URL of another spreadsheet, report!... is the name of the tab in another spreadsheet and the data range.
This kind of referencing of another spreadsheet's URL works with =importrange("https://docs.google.com/spreadsheets/d/1qOzV/","report!A2:B2"), as I realized from different examples.
But with HLOOKUP while doing so I get an error:
Wrong number of arguments to HLOOKUP. Expected between 3 and 4 arguments, but got 5 arguments.
It seems, that the spreadsheet URL is counted as separate parameter.
How do I correctly reference the URL, the sheet name and the data range?
PS: I tried to chain HLOOKUP and importrange, as mentioned in https://stackoverflow.com/a/39305031/1992004 - but fail on it, got just #REF.
My formula was
=HLOOKUP(A2,IMPORTRANGE("https://docs.google.com/spreadsheets/d/1qOzV"; "report!$A$2:$B$2"),2,0)

you are searching the content of cell A2 against imported range A2:B2 and if the match is found you returning the 1st row (of the whole dataset) of imported range after match eg. that's cell B2 of report!$A$2:$B$2. in other words range A2:B2 is one row so you cant return 2nd row from the one-row matrix, therefore valid formula is:
=HLOOKUP(A2,IMPORTRANGE("1I69LQ37hA5NjjJmuwmWkrDI_daiU_cnYDrUBpMm","report!$A$2:$B$2"),1,0)

Related

Combining a Cell Reference and Wildcard as Criterion in Google Sheets CountIf Formula

I'm struggling with writing the proper syntax for this formula in Google Sheets. In one sheet called Game Log, in the H column I have data that can be a range of names (1 - 10 names per row). I'm trying to construct a COUNTIF statement that would search for the name in all the rows for that column. There can be several other names in the same column so I need to use the wildcard * to find any occurrence of the name in each row. So for example, the current code below would count all occurrence of Adam in the rows.
=COUNTIF('Game Log'!H3:H102, "*Adam*")
What I would like to do is replace the hard codes "Adam" with a cell reference (in this case B2). Is it possible to combine that cell reference with the wild card? The know the code below doesn't work (as it would return text counting occurrences of B2), but is something like this possible?
=COUNTIF('Game Log'!H3:H102, "*B2*")
Have you tried something like this?
=COUNTIF('Game Log'!H3:H102, "*" & B2 & "*")
That ought to look for any string value, followed by the cell value, followed again by any string value. It's essentially just performing separate checks, in sequence, which allows you to search for different value types (in this case string wildcard + cell value + string wildcard).

modify number from cell reference in QUERY function (Google Sheets)

Is it possible to modify a number from a cell reference within the syntax of a QUERY function in Google Sheets without a helper cell/column?
If I have "5" in a cell, can I reference that cell and somehow subtract 1 when using the LIMIT option in the QUERY syntax so it returns four results?
I am including a sample sheet below as well as working and nonworking formulas.
link to sheet & cell
https://docs.google.com/spreadsheets/d/1lyCK5eIEQYjGFOxh5T_4BxeuDS-1zvMLq80IYn0dc38/edit#gid=1018697126&range=B1
working formula:
=QUERY(INDIRECT(currentTable),"limit "&B1&"",1)
nonworking attempt:
=QUERY(INDIRECT(currentTable),"limit "&B1&"-1",1)
You can just subtract 1 from B1 instead before passing it into the query.
=QUERY(INDIRECT(currentTable),"limit "&B1-1,1)
Output:

Troubleshooting formula with array - array arguments are of different size to EQ

In Google Sheets, I have a formula that displays the value of an item in a row if one of its cells contains any of the values listed in a different sheet. It looks like this:
=ARRAYFORMULA(IF(OR(L2 = ZRSKUs!$A$1:$Z$12005), O2, "0"))
If L2 contains any of the values in sheet ZRSKUs, this formula displays the value of the item, which is held in O2. If I drag the formula down it produces the value of every column and I can then get a SUM of this column. I wanted a way to do this without having to drag the formula down every single row (this spreadsheet has about 20,000 rows so it takes a long time to do). I also wanted the formula to add it up too, so it is all done in one cell.
I tried editing the formula to do this, and this is what I came up with:
=ARRAYFORMULA(SUM(IF(OR($L3:$L = ZRSKUs!$A$1:$A$500), $O3:$O, "0")))
However, this gives me an "Array arguments to EQ are of different size" error. I tried adjusting the number of rows in the ZRSKUs sheets so it had the exact same number as my other sheet, but this made no difference.
I'm not sure what's going wrong, so any help or advice would be greatly appreciated!
You get the error because that is not a well-formed array formula, as $L3:$L and ZRSKUs!$A$1:$A$500 are not equal in length. We could rectify this by using another function for the lookup, in this case, MATCH:
=ARRAYFORMULA(SUM(IF(ISNA(MATCH($L$1:$L, ZRSKUs!$A$1:$A$500, 0)), 0, $O$1:$O)))

How can I correctly combine these two functions

I am attempting a formula which outputs data from within a range depending on the matching criteria. So for example, if the columns Food category is Taco it then pulls from a list of ID numbers that correspond with a taco. I have a working formula
=IFERROR(INDEX(IMGID!C:C,MATCH(C5,IMGID!A:A,0)))
the issue is it only outputs the first ID from the respective range, so I thought I could include a formula that randomly pulls a cell from within a matching range. This formula
randbetween(1,counta(IMGID!C:C)
I believed I could simply combine the two and replace IMGID!C:C which is where the output or range comes from with
randbetween(1,counta(IMGID!C:C)
for this formula
=IFERROR(INDEX(randbetween(1,counta(IMGID!C:C),MATCH(C5,IMGID!A:A,0)))
but it doesn't work. It only displays an empty cell and I am at a lost
I have tried this formula
=IFERROR(INDEX(randbetween(1,counta(IMGID!C:C),MATCH(C5,IMGID!A:A,0)))
which is a combination of
=IFERROR(INDEX(IMGID!C:C,MATCH(C5,IMGID!A:A,0)))&randbetween(1,counta(IMGID!C:C)
=IFERROR(INDEX(IMGID!C:C,MATCH(C5,IMGID!A:A,0)))*randbetween(1,counta(IMGID!C:C)
There are no error messages only an empty cell where the formula is placed when using
=IFERROR(INDEX(randbetween(1,counta(IMGID!C:C),MATCH(C5,IMGID!A:A,0)))
On the other hand,
=IFERROR(INDEX(IMGID!C:C,MATCH(C5,IMGID!A:A,0)))
works but it only outputs the first option from within that range...I need variation and would like to output randomization of options from the list of possibilities within a range. This is the random formula
randbetween(1,counta(IMGID!C:C)
which works fine and I assumed I could just paste it into the earlier formula
delete B2:C in Missing_Photo sheet and paste this in B2:
=ARRAYFORMULA(IFERROR(VLOOKUP(C2:C, IMGID!A2:C, 3, 0)))
and this in C2:
=ARRAYFORMULA(IFERROR(VLOOKUP(A2:A, Storefront!B2:C, 2, 0)))

Google spreadsheets: conditional formatting with custom formula based on values from different sheet

I have a google spreadsheet with two sheets. On the first sheet, the items are listed in column A, and their types are in column B.
On the second sheet, I reference to the first sheet's column A with the formula: =UNIQUE(Sheet1!A:A).
Then I want to color the items in the 2nd sheet based on the item type (1st sheet's column B*). I try to add conditional formatting using the formula =Sheet1!$B:$B="Type1", but when I try to save rules, it says the formula is invalid.
What would be the correct formula for this case?
You cannot reference cells directly in the conditional format formula. Also, I do not think that formula would work.
First, you need the VLOOKUP function to get the object's type.
Here's an example of using this function. The difference would be that the corresponding data in the first parameter would be preceded by the sheet name in your case.
See this image:
As you can see, VLOOKUP searchs for the item from D in the matrix A2:B4, and then returns the corresponding value (the value in the same row) in the second column of the matrix, which is column B.
So if you to apply this formula to conditional formatting, you would have:
=VLOOKUP($D$2:$D;$A$2:$B$4;2)="Dragon"
The first parameter of VLOOKUP has to be a range, and I started it from D2 so it would not match the header. In your case, it would become:
=VLOOKUP($D$2:$D;Sheet1!$A$2:$B$4;2)="Dragon"
But as you cannot use references directly, you need to use the INDIRECT function. It receives a cell range as a string and returns a reference to that range. It's the same as using references directly, but in this case you add an extra step (go figure). So the formula finally becomes:
=VLOOKUP($D:$D;INDIRECT("$A$2:$B$4");2)="Dragon"
You can choose any range to apply the format if you are using the new version of Spreadsheets. You could, for example, color the entire row or just a single cell.

Resources