Google Spreadsheet vlookup with arrayformula PLUS multiplication of returned value(s) - google-sheets

I have my VLOOKUP with ArrayFormula working thanks to Adam's (AD:AM) brilliantly spelled-out solution (https://productforums.google.com/forum/#!searchin/docs/parallel$20lookup$20solution/docs/36A0epDlIdE/qnywZst0DioJ)
So in col J this is what I have:
=ArrayFormula(VLOOKUP(H2:H;ProductTable!A2:C;3*SIGN(ROW(H2:H));FALSE))
Works great. However, I would like to then take the returned value(s) from that formula in col J and multiply it against the Qty value(s) that are in row I.
Obviously I could add an extra helper column in col K...
=ARRAYFORMULA(I2:I*J2:J)
...but I was hoping to avoid adding yet another column to my Query results, especially since the returned results in col J have no visible purpose on the worksheet - they are meant to be used strictly for mathematical purposes only.
I've attempted multiple ways of slipping that formula into the ArrayFormula / VLOOKUP function in col J, but I've had no luck thus far.
Maybe it can't be done(?), or maybe I could just benefit from a fresh set of eyes looking at this issue.

Never mind. I'm not sure why this didn't appear to work when I had tried it before, but out of desperation I just walked away for a while, and then just re-tried everything again.
And this time I get the results that I was looking for:
=ArrayFormula(VLOOKUP(H2:H;Backend_Product!A2:C;3*SIGN( ROW(G2:G));FALSE )*I2:I)
(a bit of a DUH, so maybe I had originally referenced the wrong column or something)

The post you referenced is from 2011. I think that use case has been resolved since then.
I have a column using the formula =ArrayFormula(VLOOKUP(J$2:J,$C$2:$D,2,FALSE)). I created a check column with =VLOOKUP(J2,$C$2:$D,2,FALSE) which I dragged down a number of rows.
It appears that, in the array formula, J is being iterated just as it is in my dragged formula, while C:D are fixed. Both the original column and check column have the same result data so far as I've dragged the check column down.
Caveat: I did not do an exhaustive search or create a particularly clever test case. I just eyeballed a good heaping of rows of actual data.

Related

How to get only one of two repeating values

The Issue
In simple terms, I am trying to set a formula for an alternating pattern. The issue I keep running into is the fact that there are two alternating values, and Google Sheets doesn't like to repeat only one of those values without the other.
I have created an example sheet to demonstrate my issue. In Column A, a date is input. Column B and Column C then autofill with the day of the week and AM or PM respectively. Every other value in Column C alternates between AM and PM. I am trying to set it up so that the row is blank until a value in input in Column A. The issue comes when there is an odd number of Dates in Column A. Note that the alternating AM/PM pattern will never change.
What I've Tried
As seen in the image above, there are three main methods that I have tried. The data in C2:C8 is the desired result.
Method 1:
E2: =transpose(split({rept(join(";",{"AM";" "})&";",(roundup(counta(A2:A9)/2)))},";"))
F3: =transpose(split({rept(join(";",{"PM";" "})&";",(counta(A2:A9)/2))},";"))
These formulas work separately, and best represent what I am trying to accomplish, but I have not found a way to combine them to work together in one column.
Method 2:
H2: =transpose(split({rept(join(";",{"AM";"PM"})&";",(roundup(counta(A2:A9)/2)))},";"))
This is essentially the same as Method 1, but put into one formula. The issue here is that Google Sheets doesn't like to repeat half a number of times. So if the number of times to repeat (counta(A2:A9)/2) contains a half (i.e. 3.5), it will still round down to the nearest whole number.
Method 3:
J2: =ArrayFormula(TEXT(SEQUENCE(3),"")&{"AM";"PM"})
This one appeared most promising to me because when incrementing by one, it added one row, but I quickly ran into the issue where if I went over a sequence number of 2, it threw the error Array arguments to CONCAT are of different size.
References
I have used various search terms and websites to try to solve this, and have yet to find something that works. I may be missing something very simple, though, and hopefully this is a quick solution.
Example Sheet:
https://docs.google.com/spreadsheets/d/1I3EtptFLfDHpAQ8AR6Lwa01dSpJ3Cy8MTX1_OjHExSc/edit?usp=sharing
All my formulas are derived from the websites below:
REPT Function in Google Sheets
How to Repeat Multiple Columns N Times in Google Sheets
Delete everything in Col C (including the header) and place this formula in C1:
=ArrayFormula({"AM/PM"; IF(A2:A="",,IF(COUNTIFS(A2:A,A2:A,ROW(A2:A),"<="&ROW(A2:A))=1,"AM","PM"))})
The COUNTIFS finds the number of matches for the date "up to this row" for every row. Since that count will (or should) only ever be a 1 or a 2, the IF makes easy work of assigning "AM" or "PM" accordingly.
If I understand correctly it is enough to use ISEVEN function to alternate by rows:
=ArrayFormula(IF(A2:A,CHOOSE(ISEVEN(ROW(A2:A))+1,"PM","AM"),))

Google sheets, two-sheet dependent conditional formatting

My problem is probably trivial ... However, I was looking for similar problems and their solutions either do not work for me or I can not apply them.
I have 2 sheets - SheetA and SheetB. They are identical. I want to select every cell in SheetA that is no longer identical to Sheet B.
I was able to use (found here on Stack Overflow) such a function in conditional formatting:
= A1 <> INDIRECT ("SheetB! A" & ROW ())
It works if the range is column A. I know that I can apply this function to each column separately, but there is certainly a way that I can apply the same formula to the whole worksheet.
Will there be anyone who can show me the correct formula?
Edit: I tried to use above formula to every column... And my file become to work very slow... So whoever wants to do the same... think again.
After some tries I decided to move everything from SheetB to SheetA. I paste it a 1000 rows under data of Sheet A. Works fine without "indirect" function. No slow downs. It is not a perfect solution but it works.
But even after my problem is solved different way, I would like to know what is the correct formula for my problem... it might be useful for the future with smaller amount of data.
Solved ;)
You should be able to use the Address function to get the address of the current cell from its row and column:
=A1<>indirect("sheetB!"&address(row(),column()))
or for case-sensitive match:
=not(exact(A1,indirect("sheetB!"&address(row(),column()))))

How to use AVERAGEIFS within ARRAYFORMULA

I am trying to use AVERAGEIFS inside ARRAYFORMULA. Looking at other questions, I have come to the conclusion that it is not possible without using QUERY function.
My intention is to average the values of a column whenever they share the same ID.
I think this question comes pretty close to what I need, but I haven't been able to replicate and adapt its solution on my own sheet.
In this sheet I show the result I expect (I got it by dragging the formula). I've also reviewed the Query Language Reference, unsuccessfully.
Thanks a lot for your time and effort.
So the formula should be
=ArrayFormula(iferror(sumif(A2:A,A2:A,B2:B)/countif(A2:A,A2:A)))
Note that if there were any text values in the points column, this would still return a result (because count would be greater than zero) - you could instead use
=ArrayFormula(if(isnumber(B2:B),(sumif(A2:A,A2:A,B2:B)/countif(A2:A,A2:A)),""))
If you had a mixture of rows with text and rows with numbers for any ID, this would return a smaller result than the avg or average formula. This is a limitation of this method. You can't put an extra condition in (that column B has to contain a number) because you would need countifs and countifs isn't array-friendly. It still seems strange that AFAIK countif and sumif are the only functions out of this family that are array-friendly while countifs, sumifs, averageif etc. are not.
you can do:
=ARRAYFORMULA(IFERROR(VLOOKUP(A2:A; QUERY(A2:B; "select A,avg(B) group by A"); 2; )))

Is there a way to use ARRAYFORMULA to find the most-recent even input of a column?

SOLVED EDIT
Thank you for the help. Solution here.
ORIGINAL POST
I have made a google sheet to describe the issue I am facing linked here (https://docs.google.com/spreadsheets/d/1yK6ZAX8BFnEqiuQO9HIxuY0l62ewDDccj-8EN1r2i2w/edit?usp=sharing).
I will also describe in words, below, the problem I am facing, along with the solutions I have tried.
The data of column A are random single-digit (0-9). I would like column B to show the most recent even number from column A, but only up to a specific row. That specific row is the row corresponding to the row of the cell in column B. In other words, in cell B7, I want to find the most recently entered even number of column A, specifically only on the range A2:A7 (A1 contains a column header).
This is actually a pretty simple formula, and I can get the desired outputs by simply checking if the value in a cell in column A is even and then returning the value of that cell if it is, or the output of the cell above if it isn't. So the formula would look something like: ​=IF(ISEVEN(A7),A7,B6)​
However, my problem is that the length of the data in column A will be growing as more data are entered, and my current solution of using the fill handle to copy the formula to new cells is inelegant and time-consuming. So my desired solution is to use an array formula entered into the first cell of column B (B2), capable of returning the same value as the other formula. The formula I tried to enter to perform this was the following: ​=ARRAYFORMULA(IF(ISEVEN(A2:A),A2:A,INDIRECT(ADDRESS(ROW(A2:A)-1,2))))​
However, as some of my previous work with arrays has taught me, not all formulas iterate as expected down the array. The formula seems to be able to return the correct output on lines which are already even, but it is unable to return the expected most-recently entered even number for all the other lines. It appears that the formula is not able to appropriately interpret the ​value_if_false​ argument of the ​IF​ formula.
I'm a little new to scripting, so I'm still trying to learn, but I also tried to dabble around with custom functions to no avail. I'm still wet behind the ears when it comes to coding, which is why I've been so lenient on the built-in formulas of Google Sheets, but I fear I may have reached the limit of what Sheets formulas can do.
I am open to trying new approaches, but my only real constraint is that I would really like for this to be a one-touch (or even better no-touch) solution, hope that's not too far beyond the scope of this issue. Any assistance would be much appreciated.
EDIT
After rubber-ducking the problem here, I went back and tried to use the OFFSET formula, hoping I could get it to play nicely with the array formula. Alas, I was unable, but I thought I should at least post my progress here for reference.
Attempt with offset
Still working at it!
Doing a vlookup on the row number seems to work for me
=ArrayFormula(if(A2:A="","",vlookup(row(A2:A),{if(iseven(A2:A),row(A2:A)),A2:A},2)))
Note: if there are no even numbers in range for some rows, it will produce #N/A for those rows.

SUMIF with FIND as criteria

I'm trying to summarize data from several Google spreadsheet' sheets in a single one but I have some issues with SUMIF and FIND.
To Sum data from another sheet I have to use this (at least that's the only solution I've found)
=SUM(INDIRECT(""&A6&""&"!E2:E"))
Where I have the name of my sheet on A6.This makes everything easy because I have a column (A) with all the names of the sheets. I haven't found something like Sheets[1] in Google Docs.
My next step was to Sum Times from a specific column but remove a specific values, which in this case is 1 that get transformed internally 24:00:00 since it's a time column:
=SUM(INDIRECT(""&A6&""&"!D2:D")) - SUMIF(INDIRECT(""&A6&""&"!D2:D");"24:00:00")
Here I tried to do everything with a single SUMIF but I have no idea how. NOT("24:00:00") didn't work so I settled to this.
The last part is the most difficult and I'm not able to solve it.
I have a column with month names (for example) and I want to sum some data only when the month name contains "er". Here is what I thought:
=SUMIF(A6:A16,ISNUMBER(Find("er")),G6:G16)
This gives me always 0
(Note that the last one contains A6:A16 instead of the whole INDIRECT part because I am still testing it in a single sheet.)
Any Idea what I'm doing wrong?
I don't know why the above SUMIF doesn't work, what I've tested and works is:
=SUMIF(A6:A16,"*er*",G6:G16)
SUMIF is NOT SUM + IF as I thought. I hope it will help someone else.

Resources