How to apply formulas in rows with unknown no of columns? - google-sheets

This works:
This does not:
I don't know why.
EDIT:
Thanks to Marios this works:
=ARRAYFORMULA( IF(B5:5 = "Start","",IF(
B6:6-A6:6>-1,B6:6-A6:6,0)))
"Start" to be changed to a named range with the actual date at the top of the sheet.

Explanation:
You are trying to execute this formula:
=ARRAYFORMULA(C6:6-B6:6)
in cell C7.
The issue with that is this part B6:6. This is a range of columns starting from B until the last column in your sheet, but since you put that formula in cell C7 your starting point is column C.
Essentially, you want to put the range of values from column B until the last column of the sheet but your available space is from C until the last column of the sheet and therefore you lack 1 column as the error also suggests.
An analogy would be:
fit a big box inside of a smaller one with a size difference of one column. In this case the big box is the range of B6:6 and you are trying to put it in a smaller box of a range C6:6.
Solution:
Try to put that formula on cell B7 and it will work. Don't drag it, because the big range will shift to column A and you will face the same issue. Just use the same exact formula on cell B7:
=ARRAYFORMULA(C6:6-B6:6)
While this might not be your goal, it explains what is the current issue you are facing and what to do in order to fix it.
Update based on your solution:
=ARRAYFORMULA(iferror(IF(B5:5 = "Start","",IF(B6:6-A6:6>-1,B6:6-A6:6,0)),""))
I added an iferror check to catch the first error value caused by the string.

You should use this:
=ARRAYFORMULA(IF(B5:5 = "Start","",IF(B6:6-A6:6>-1,B6:6-A6:6,0)))

Related

Google Sheets - ArrayFormula - XLOOKUP

so I have this situation:
I have dates (mmm-yy) in one row (horizontal) and other dates in one column (vertical) I'm trying to match them and if the dates match, then ArrayFormula-XLOOKUP but since the result cell may overwrite the next cell with formula, I've got Circular dependency detected.enter image description here
Please check attached image, I need some advice on how to workaround this issue.
I've tried arrayformula with xlookup, also possible with filter but don't know how to avoid circular dependency.
The reference F2:F points to column F, starting in cell F2 and extending all the way to the bottom, while you apparently want to point to row 2 starting in cell F2 and extending all the way to the last column.
To fix that, replace F2:F with F2:2.

How to Transpose Rows to Columns Towards Left Columns? In Google Sheet

SECOND IMAGE CLICK NUMBER 1 I Want To Transpose Row Value Range A2:A50 To Column CZ2 To BC2. Formula Should Be Given IN CZ2. AND VALUE SHOULD GET IN REVERSE OR LEFT COLUMNS.[First IMAGE Click Number 2] 2. If I Give Transpose (AO2:AO50) In CZ2 it Will go range from CZ2 To EW2. I Want Transpose in Reverse Columns. If I Increase Row Value AO2:AO60 It Should Flow Towards Left From CZ2 To AS2. I Mean Transpose Should work towards Left Side Columns. Its Ok with any other formula If Not Transpose. Hope My Question is Understandable. Someone Help Me Out. Thank You In Advance.
It's not clear why you would want to do this. However, the end goal can be achieved by placing the following formula in cell B2 (not CZ2):
=ArrayFormula(IFERROR(VLOOKUP(COLUMNS(B1:1)-COLUMN(B1:1)+ROW(A2)+1,{ROW(A2:A),A2:A},2,FALSE)))
Try it and you'll see what I mean.
The formula is written to be flexible. So if you add or subtract data from A2:A, the value in A2 will always be in Row 2 of the last column to the right in the sheet; and all other values will work backward from there.
If you always want to start to backward progression in Column CZ and Column CZ is not (or may not always be) your rightmost column, you can use this version:
=ArrayFormula(IFERROR(VLOOKUP(COLUMN(CZ1)-COLUMN(B1:CZ1)+ROW(A2)+1,{ROW(A2:A),A2:A},2,FALSE)))
Just understand that, if you don't have columns at least through Column CZ, this formula will fail to work as expected.
I recommend using the first formula I supplied above, since it will always work, no matter how many columns there are, filling backward as far as to the formula column (B2) as needed.
Understand also that if you have more than 103 rows of data in A2:A, that would be more than could fit between B2 and CZ2; so only the first 103 would be displayed.
ADDENDUM (after reading first two comments below):
The principle is the same if you want to run results from "CZ to BC"; only in this case, you want to limit the results to no more than 50.
Place the following formula in BC2:
=ArrayFormula(IFERROR(VLOOKUP(SEQUENCE(1,50,ROW(A2)+50-1,-1),{ROW(A2:A),A2:A},2,FALSE)))
To reiterate, you cannot run formulas that will fill or columns backward. (Even if the sheet is set to right-to-left font with Column A appearing at the far right, the formula is still filling A-Z according to that setup.) However, if you know that you want a 50-column range reserved and you want the answers to go backward, this can still be achieved by placing the formula in the first of the 50 columns rather than the last, as I have proposed above.

How to use ARRAYFORMULA with OFFSET to previous row without getting circular reference error

Example sheet: https://docs.google.com/spreadsheets/d/14ma-y3esh1S_EkzHpFBvLb0GzDZZiDsSVXFktH3Rr_E/edit?usp=sharing
In column B of ItemData sheet, I have achieved the result I want by copying the formula into every cell in the column, but I want to solve this using ArrayFormula instead.
In column C I have achieved the same result using ArrayFormula. However, for addition, column C is referring to cells in column B, while column B is referring to cells in column B. I.e. every cell in column B is adding 1 to the cell on the row above.
If I select the C3 formula text and paste it into the cell edit field for cell B3 (to not screw up cell references during copy - I know I could make them static references, but this is not my problem), the cell gets an error value of
#REF!
Error
Circular dependency detected. To resolve with iterative calculation, see File > Spreadsheet Settings.
Do note that the additions that need to be done are the same in both cases: Add 1 to the value of the cell on the previous row, so there is no circular reference involved. There is a starting value provided in B2, and cells in B3 and downwards should use the data from the B cell in the previous row.
Also, note that I did try File->Spreadsheet settings and enabling circular reference computation with max 25 items, but this only fills in the first two cells (B3 and B4).
How can I solve this problem? I would prefer having something like ArrayFormula, where the formula only exists in a single cell. But copy-pasting would be acceptable as long as any new rows, inserted in between or added at the bottom, would get the same formula added in column B.
Will matching items always be consecutive? It seems that way since you're comparing each Item cell to the cell above it right in your formula logic. That breaks an [unwritten?] rule of spreadsheet normalization; values' addresses themselves generally should not be treated as data.
IF you're committed to it though, have you considered explicitly using location as a data source? Example:
=ARRAYFORMULA(IFS(
NOT(LEN(A3:A40)),,
ROW(A3:A40)-3-MATCH(A3:A40,A$3:A$40,0)<=VLOOKUP(VLOOKUP(A3:A40,Items!$A$2:$D,2,false),DataPerColor!$A$2:$B,2,false),ROW(A3:A40)-3-MATCH(A3:A40,A$3:A$40,0),
true,
))
Just like your formulas, all that does in English is:
for each row,
if there's no Item, don't output any ItemData,
if the number that belongs in this cell¹ is less than or equal to the lookup, print it,
otherwise, don't output any ItemData
But then what is ¹ "the number that belongs in this cell" and how can we calculate it without using column B? I abuse locations of things to get it. Looking down your row B, each number that appears is just:
this row's number,  minus  
the row where items start [always 3],  minus  
the row number [in just the Item rows] of the first row containing this row's Item
Using the second-to-last ItemC as an example: the first ItemC is the 16th item listing, and the one we're looking up… the "second-to-last ItemC" is in row 21 of the sheet. 21-3-16 = 2 …the number you wanted.
If you can stomach that, it's a single formula and does work according to your specifications.

Google Sheets: Conditional formatting on Multiple Rows based on multiple cell values

I am trying to use conditional formatting to color a column based on the value of the column itself, plus another column. But I am having issues.
If the value in H is "Race Expense" and the K cell is empty, I want the K cell to be colored in red. But as you can see below, it is not working. The results I am getting (the colored cells) are incorrect.
Here's my format condition:
Here's the actual formula (since you can not see all of it above):
=AND(($K667=""),($H667="Race Expense"))
Any ideas what's wrong?
Ok, so I feel like an idiot. Thanks to a comment on my original post the issue is solved.
Since my selected range was K666:K671, I had to modify my formula to use the first row of the range.
I was originally using this formula:
=AND(($K667=""),($H667="Race Expense"))
But by just changing it to this one it solved the issue:
=AND(($K666=""),($H666="Race Expense"))

Detecting what row a google spreadsheet is in

Is there a way to make a formula that would detect what row it's in and I can copy and paste it into all instead of typing out a different formula for each one, since I have a very big spreadsheet.
I.E Divide column A, Current Row by two.
If I understood this correctly, you can have arrayformula in cell F2 that references E2:E. No need to figure out the rows... try:
=ArrayFormula(if(len(E2:E), E2:E/2,))
Note: according to your locale you may have to replace the comma's with semi colons.

Resources