Google Sheets Reference form Index function - excel

I have reference based index function in an xlsx spreadsheet
=SUM(B10:INDEX(B10:AJ10,$D$5-1))
However importing this spreadsheet in google sheets broke the function as Index doesn't return reference any more instead return the value at the index.
I wonder how can I solve this problem in google sheets.

That formula doesn't look correct. You are using the INDEX function for the extents of the range in a single row but you are returning the row number, not the column number to extend to.
=SUM(B10:INDEX(B10:AJ10, , $D$5-1))
That small modification should correct the range. With 7 in D5 this would be SUM(B10:G10) in Excel.
However, Google-Docs cannot use INDEX like that. Use the OFFSET function instead.
=SUM(offset(B10:AJ10, 0, 0, 1, $D$5-1))

Related

Return contents of the cell above the one indicated in VLOOKUP using ADDRESS, INDEX, MATCH, and/or CELL function

I am trying to use a date in Sheet 1 and using Vlookup to find this date on Sheet 2 and return the value/contents onto to a cell in sheet of the cell directly above that date in sheet 2.
This is the Formula I used that you can see
=INDEX('AUSSIE Dly'!$A$3:$A$2000,MATCH($B$9,'AUSSIE Dly'!$A$3:$A$2000)-1)
I have tried using Index and match but to no avail. Please help.
You should use
=INDEX('AUSSIE Dly'!$A$3:$A$2000,MATCH($B$9,'AUSSIE Dly'!$A$3:$A$2000, 0)-1)
The added zero indicates using an Exact Match.

How do I use INDIRECT inside an Excel array formula?

The situation
In the sheet "Planning" I have an area that contains pairs of sessions (strings) and hours (numbers) in adjacent cells (e.g. D11 and E11, I12 and J12 etc.) One session can occur multiple times.
D11:E11 is | Foo | 8 |
I12:J12 is | Foo | 4 |
In another sheet, I want to find a session in the Planning sheet and return an array with all the hours booked on that session (to calculate a total)
I use an array formula with a conditional and intend to use the SMALL function to retrieve the results from the array
The problem
The following formula returns all the correct references to hours booked on "Foo", so far so good.
=IF(Planning!$D$11:$CV$18="Foo";ADDRESS(ROW(Planning!$D$11:$CV$18);COLUMN(Planning!$D$11:$CV$18)+1;;;"Planning"))
{"Planning!$E$11"\FALSE\FALSE\FALSE\FALSE\"Planning!$J$12"}
However, if I use the INDIRECT function to retrieve the values of those references, they always return the value of the first reference in the array ("Planning!$E$11")
=IF(Planning!$D$11:$CV$18="Foo";INDIRECT(ADDRESS(ROW(Planning!$D$11:$CV$18);COLUMN(Planning!$D$11:$CV$18)+1;;;"Planning")))
{8\FALSE\FALSE\FALSE\FALSE\8}
How do I retrieve the correct values? Or should I tackle the problem in a whole different way?
Screenshots
The planning sheet
The overview I want
Since I was mainly interested in the total of planned hours, I eventually used the following formula:
=SUM(SUM(INDIRECT(IF(Planning!$D$11:$CV$18="Foo";(ADDRESS(ROW(Planning!$D$11:$CV$18);COLUMN(Planning!$D$11:$CV$18)+1;;;"Planning"));"$U$19"))))
IF: Create the array with references to the Planning sheet if the string is found. If it's not found, add the reference $U$19.
Using INDIRECT, replace all references with the values in the Planning sheet. $U$19 contains the value 0.
Then use SUM twice to sum up all the values. I don't know why, but see
Is it possible to have array as an argument to INDIRECT(), so INDIRECT() returns array?
https://superuser.com/questions/1196243/simplify-a-sum-of-indirect-cell-values
Indirect doest work in most array formulas. If you give it a string that refers to an array, like "A1:A10" it it returns those cells as expected but thats about it. You can use that array as the input to another function but you cant send an array output from another function to INDIRECT(). (Or at least i have not figured out a way)
Try using the INDEX function with the ROW function.
INDIRECT("A1:A10") is similar to
INDEX(A:A,ROW(A1:A10))
However the former is less flexible.
Comsider:
INDEX(A:A,FILTER(ROW(A1:A10),NOT(ISBLANK(A1:A10))*ISNUMBER(A1:A10)))
This returns an array containing the numerical values in the range but does not treat an empty cell as zero. Watch your order of operations and parenthesis.
The product NOT(ISBLANK(A1:A10)*ISNUMBER(A1:A10) is the inner product of two vectors of boolean values.
ROW(A1:A10) creates a vector of row values of the of the elements in that range. Then filter throws out any where the corespinsing element of the boolean vector is 0. Index then returns an array of values of the cells in its range coresponding to those rows. The range given to INDEX could be any row in fact. Not just the one your selecting on. Using the entire column (for example A:A) allows excel to automatically update the references if you move the source data, for instance if you insert a header row. If you use a specific range you will need to add an offset to the row value and it will not automatically update refernces. (Without a far more complex formula)

Searching non-leftmost values with VLOOKUP-like function in Excel

I have a question about excel function.
The question is:
I want to use VLOOKUP-like function, but VLOOKUP only search leftmost row.
Is there any function that searches non-leftmost row (you can select) and the behavior is almost same as VLOOKUP function?
If you don't understand, please see this picture.
I want to do like this in Excel.
Thank you for reading.
INDEX MATCH Combo
You can use combination of 2 functions:
INDEX function
The INDEX function returns a value or the reference to a value from within a table or range.
MATCH function
The MATCH function searches for a specified item in a range of cells, and then returns the relative position of that item in the range. For example, if the range A1:A3 contains the values 5, 25, and 38, then the formula =MATCH(25,A1:A3,0) returns the number 2, because 25 is the second item in the range.
Example
=INDEX(Name_col, MATCH(Rank_input, Rank_col, 0)).
Equivalent, using your concrete data, assuming you have "Alex" in A3:
=INDEX($A$3:$A$7, MATCH(A10, $C$3:$C$7, 0))

Find data in whole sheet and return the value under specific header

I'm not really good with excel but I've already searched and tried lots of formulas but still can't get this done. Problem is I need a cell in Sheet1...
...to return the value of the data in Sheet2 based on the column header name. Since the values might change its column number i need to search for the header name itself to return the value. As shown on the screenshot below. the lookup value will be the number and country and return the value under price that corresponds to the row.
Use a MATCH function across the top row to return the column number.
=index(A:Z, aggregate(15, 6, row(1:999)/(A1:A999=9)*(B1:B999="US"), 1), match("price", 1:1, 0))
You may have to lock some row and column range references down as absolute with $ if you plan to copy or fill the formula to other locations.
The AGGREGATE¹ function provides the two column match for 9 and US.
¹ The AGGREGATE function was introduced with Excel 2010. It is not available in earlier versions.

Last Non-blank Column In A Row

I've found the following formula which works great when you are searching within the same sheet in Excel. So this formula works when I want excel to return the last value in row 3.
={INDIRECT(ADDRESS(3,MAX((3:3<>"")*COLUMN(3:3)),1))}
I'm struggling to use it when I want excel to return the last value in row 3 of a different worksheet. Can anyone help?
Thanks
RP
There is no need for INDIRECT in this case.
For working with different worksheets, you have to refer the worksheet within the cell addresses.
{=INDEX(Sheet1!3:3,,MAX((Sheet1!3:3<>"")*COLUMN(Sheet1!3:3)))}
Without using array formulas the same could be achieved with:
=INDEX(Sheet1!3:3,,LOOKUP(2,1/(Sheet1!3:3<>""),COLUMN(Sheet1!3:3)))
But this is basing on a strange not really documented behavior of LOOKUP which takes {1; #DIV/0; 1; 1; #DIV/0} as a sorted array.
The INDEX variants return a cell reference. So we can build dynamic ranges like:
Sheet1!A3:INDEX(Sheet1!3:3,,LOOKUP(2,1/(Sheet1!3:3<>""),COLUMN(Sheet1!3:3)))
If you are only interested in the last value
=LOOKUP(2,1/(Sheet1!3:3<>""),Sheet1!3:3)
will also suffice. But this returns the value only, not the reference.
Pro and cons for the array formula in this case:
pro: It works like it is documented. (Sheet1!3:3<>"") returns TRUE or FALSE and TRUE * COLUMN(Sheet1!3:3) gets COLUMN(Sheet1!3:3) while FALSE * COLUMN(Sheet1!3:3) gets 0. So the MAX then is the biggest column number where (Sheet1!3:3<>"").
con: It is slow. Not unusable in this case, because we work only on all cells in a row. But if we would apply this on all cells in a column, then it would be unusable slow.

Resources