Refer the sheet in the figure
For the H column, I want Hj = Gj+MAX(F)-Fj , where j = row number.
The given formula works for the second row, but when I drag to other rows, MAX value also changes. I want MAX(F2:F8) to be constant and other values to change. How can I do that?
Fix the max range like this F$2:F$8 ($ fixes the range).
Instead of dragging the formula down from cell H2, you could use an arrayformula in cell H2:
=arrayformula(if(F2:F<>"",G2:G+max(F:F)-F2:F,))
F2:F<>"" evaluates the calc whilst each cell in column F is not empty, otherwise the , at the end of the formula does nothing.
Related
I am trying to format a group of cells but I need a custom formula for when the value of a cell is greater than the value of the cell in its column of a specific row it needs to be highlighted
(The highlighted value reference point in the group is in the same row)
Please help 😞
I tried to highlight by using the default option on each column but there are way too many rows
I don't have your exact spreadsheet. Let's say your range goes from A1:Z, and that the column of reference is column E (from each row). Then you can set this formula to:
=A1 > $E1
Change A1 to the first cell of your range and $E1 with the first corresponding column of the first row of the rage (if you start row 3, then put $E3 -- and change the letter ;) )
Let me know if this works for you!
I would like to colour cell C3 red, as the value is less than the next filled cell on row 3 (E3).
You need custom formula in the formatting rules for range C2:W.
And you can use the formula below for green:
=and(not(isblank(C2)),C2>index(filter(D2:$W2,arrayformula(not(isblank(D2:$W2))))),1,1)
And make another conditional formatting rule with the same range and change > accordingly for red.
Note that the equal case does not have formatting in your example.
To understand why, there are a few components at work. I'll give an outline in case OP or any passer-by wants one.
First is how conditional formatting in Google Sheet works. I will be brief here. The range we put in the rule is C2:W. Google Sheet will use the beginning cell in that range as a reference. For C2:W, the 1st cell is C2. In the formula, the cells are read in terms of relative position to that reference cell. So when evaluating formatting for cell C2, it treats the formula as is. But, for example, when evaluating formatting for cell C3, Google Sheet iterates all non-fixed ranges by 1 row. Another example: for D3, all non-fixed ranges are iterated by 1 row and 1 column.
Whenever the formula evaluates to true, the format will be applied -- although that is subject to further formatting if you have subsequent formatting rules which apply to the given cell.
Next are the components of the conditional formula.
not(isblank(C2)) checks for blank cells and makes the whole formula only true when the cell is non-blank.
For filter() usage, please consult official documentation. I will explain how filter() is applied to your example.
In our use, we are trying to rid of empty cells in the range that is on the same row as the cell in question and goes from the next column to column W. (I am using column W because there is no known end column in your image. Please adjust to your application accordingly.) Same row as C2 means row 2. Hence the digit 2 in D2:$W2. No $ sign for row because row index is meant to iterate through our range C2:W in the formatting rule. No $ sign for D because we mean 1 column next to the cell in question and the exact column index should iterate. We fix column W because the end column does not evolve and is thus not meant to iterate. Neglecting this will not particularly change the result in your example. However, it is good to be clear with the meanings.
arrayformula(not(isblank(D2:$W2))) produces a local row array whose cells are true/false that each represents whether the corresponding cell is non-blank. filter() in turn only keeps cells from D2:$W2 for cells in arrayformula(not(isblank(D2:$W2))) that are true.
We only care about the 1st non-blank cell. To retrieve the 1st cell from a (local) array, we use index(...,1,1). (That said, omitting index() also happens to work for the 1st cell in particular because when comparing a single cell with > or < to an array range, only the 1st cell of the array is used.)
Apply a conditional formatting to the range desired (starting from cell C2) using this formula:
=IF(C2="",FALSE,OFFSET(C2,0,AGGREGATE(15,6,(COLUMN(D2:W2)-COLUMN(D2)+1)/(D2:W2<>""),1))>C2)
I'm trying to get max value between 2 cells (one is same column, previous row, another is in the same row, but different column) with an array formula. I use array, because I need it to be updated automatically row after row with each new entry in column A without adding formula to new cells each time.
Just MAX formula is following:
I3512=MAX(I3511,C3512)
This array formula gives same result in each following cell
I3513 = ARRAYFORMULA(IF(ISBLANK(A3513:A),,MAX(I3512,C3513)))
This formula also, gives me the same result in each row, as counting the max from C column.
I3513 = ARRAYFORMULA(IF(ISBLANK(A3513:A),,MAX(I3512:I,C3513:C)))
Also I tried this version, but it fails in the middle, showing wrong values.
I3513 = ARRAYFORMULA(IF(ISBLANK(A3513:A),,if(I3512:I<C3513:C,C3513:C, I3512:I)))
How to apply MAX formula to all rows in column I after row 3513, finding between previous cell and another column same row.
Suggested formula result
if just two columns use IF in row 3513:
=ARRAYFORMULA(IF(A3513:A="";; IF({I3512:I; ""}>C3513:C; {I3512:I; ""}; C3513:C)))
Use OFFSET
For example:
C3 =
{
"MAX PNL";
"N/A";
ArrayFormula(
IF(
OFFSET(A3:A1000, -1, 0) > B3:B1000,
OFFSET(A3:A1000, -1, 0),
B3:B1000
)
)
}
Bear in mind with this technique you can't use ranges like A3:A as this will give you an error:
This is because since it references two rows, it gets confused and always requires more rows.
I'm trying to make a Google spreadsheet where I want the sum of the values in the row to appear in the AH cell of that row.
The row would be populated with letters like L or X and I'm using COUNTIF to give value to the alphabet characters.
For example,
=COUNTIF(C4:AG4,"X")*9 + COUNTIF(C4:AG4,"L")*12
How can I write the range such that it looks at cells C through AG from the same row the formula is in rather than change it for every row?
You don't need to change the formula, if you write that formula in one cell and then you drag the little square at the bottom right of the cell, excel will automatically change the row number
Just copy downwards:
As you see, the row index changed to 5 automatically.
In Google Sheets I am using a filter function to pull in Names into column A and a Timestamp into column B. Every time a second occurrence of the name shows up into columns A & B of the list I want column C next to the prior occurrence to reference the new timestamp. In column D I will then calculate the difference from the names timestamp and the next occurrence of that same name.
Currently I am using the following formula:
=IFERROR(INDEX(B3:B,MATCH(A2,A3:A,0)))
If I drag this formula down it does what I need it to do, but due to how many rows are being added to the first two columns, rows are being added to the bottom of the sheet due to the filter and the formulas keep needing to be dragged down. The durations in column D are being calculated with the following formula, that automatically arrays the results and automatically expands with the filter results:
=IFERROR(ARRAYFORMULA(IF(C2:C="","",C2:C-B2:B)))
I would like my index match formula to do the same, but it seems I cannot use the index formula with an arrayformula.
I attempted to achieve this by using a vlookup combined with an offset for the range. The first row is giving me the result I want, but all the subsequent rows are not referencing the offset range, probably because the offset isn't changing with each new array result here is that attempt:
=IFERROR(ARRAYFORMULA(VLOOKUP(A2:A,OFFSET(A2:B,1,0),2,FALSE)))
Any ideas how this could be accomplished by placing a formula in one cell, or would this have to be accomplished with a script?
I have added an example spreadsheet of the current method HERE
Thanks in advance for any help.
Formula
Instead of
INDEX, MATCH and OFFSET
try the following formula
=ArrayFormula(IFERROR(VLOOKUP(
TRANSPOSE(VALUE(REGEXEXTRACT(QUERY(TRANSPOSE(
IF(FILTER(ROW(A2:A),LEN(A2:A))<TRANSPOSE(FILTER(ROW(A2:A),LEN(A2:A))),
IF(FILTER(A2:A,LEN(A2:A))=TRANSPOSE(FILTER(A2:A,LEN(A2:A))),
TRANSPOSE(FILTER(ROW(A2:A),LEN(A2:A))),
),)
),,2000000),"(\d+)"))),
FILTER({ROW(A2:A),B2:B},LEN(A2:A)),2,0)))
Formula description
This part creates a square matrix showing the row number of the value that matches if it's below of the current row:
IF(FILTER(ROW(A2:A),LEN(A2:A))<TRANSPOSE(FILTER(ROW(A2:A),LEN(A2:A))),
IF(FILTER(A2:A,LEN(A2:A))=TRANSPOSE(FILTER(A2:A,LEN(A2:A))),
TRANSPOSE(FILTER(ROW(A2:A),LEN(A2:A))),
),)
This part takes the smallest row that matches the current row (the next occurrence of the row value)
TRANSPOSE(VALUE(REGEXEXTRACT(QUERY(TRANSPOSE( ),,2000000),"(\d+)")))
This part returns the related value, if any, otherwise a blank:
IFERROR(VLOOKUP( ,FILTER({ROW(A2:A),B2:B},LEN(A2:A)),2,0)))