Let's say in A1 I have the number 500 and in A45 I have the number 323.
How do fill cells A2->A44 with numbers that evenly reduce down to the end number of 323 (A45)?
go to File
select Spreadsheet settings
choose Calculation
and turn on Iterative calculation
then use this formula:
=ARRAYFORMULA(INDIRECT("A"&
MAX(IF(A3:A<>"", ROW(A3:A), )))+SORT(ROW(INDIRECT("A1:A"&
MAX(IF(A3:A<>"", ROW(A3:A), ))-2)), 1, 0)*(A1-INDIRECT("A"&
MAX(IF(A3:A<>"", ROW(A3:A), ))))/(
MAX(IF(A3:A<>"", ROW(A3:A), ))-1))
To get the step, find the difference between A1 and A45 and divide that by the number of rows between the two cells plus 1.
Then multiply the step by the sequence 1, 2, 3... N where N is the number of rows between the two cells, and subtract the product from A1, like this:
=arrayformula( A1 - sequence(rows(A2:A44)) * ((A1 - A45) / (rows(A2:A44) + 1) ) )
To get integers that will at various steps be one larger or smaller than others, add round(), like this:
=arrayformula( round( A1 - sequence(rows(A2:A44)) * ((A1 - A45) / (rows(A2:A44) + 1) ) ) )
Related
I need column J to look at multiple different scenarios and return 1,0 if any are true.
In J1 (and continuing down column J)
if B1 is a number and
B2 and B3 are blank and
the sum of G1:G3 is 2 or more
or
if B1 is a number and B2 is a number or if B2 is "-" and B3 is a number
then return 1
However, if in the range of H1:H3 there is a FALSE,
then an additional row must be added to the sum of G1:G3.
If B1 is "-" then J1 is empty
EXAMPLES:
B1 is a number, B3 is also a number, so J1 should read 1
B11 Is a number. B12:B13 are "-". So then we look to the sum of G11:G13. That equals 2, so J11 should read 1.
B23 is a number, and B24:B25 are "-". So then we look to the sum of G23:G25. However H25 is False, so now we look to the sum of G23:G26. If H24 is false too, then we would look to the sum of G23:G27.
One goal is to always add three applicable values from G, looking at H to determine applicable values.
I could split up these formulas into multiple columns if needed.
SAMPLE SHEET
I worked out this formula
=if(B1="-","",if(or(IF(AND(ISNUMBER(B1),SUM(G1:G3)>=2,B2="-",B3="-"),1),if(and(isnumber(B1),or(isnumber(B2),isnumber(B3))),1)),1))
But have no idea how to add the stipulation for column H when a FALSE is present.
I need a single cell formula to create a sequence of numbers with a limit in Google Sheets as shown in the image.
3 rows repeat the value
then Increment by 5
Use this formula, you can adjust the Sequence() and REPT(rg&",",3) parameters to your need.
In this example Sequence(number_of_unique_numbers,columns,start_at,increment_by)
And REPT(rg&",",Repeat_N_times)
=ArrayFormula(FLATTEN(SPLIT(BYROW(SEQUENCE(3,1,5,5),
LAMBDA(rg, IF(rg="",,REPT(rg&",",3)))),",")))
Option 02
Based on Themaster - answer we use lambda with the names.
u unique s start r repat n time
=LAMBDA(u,s,r, FLATTEN(MAKEARRAY(u,r,LAMBDA(u,r,u*s))))
(4,5,3)
Used formulas help
ARRAYFORMULA - FLATTEN - SPLIT - BYROW - SEQUENCE - LAMBDA - IF - REPT - MAKEARRAY
Use MAKEARRAY with FLATTEN. Multiply the row index number by 5:
=FLATTEN(MAKEARRAY(4,3,LAMBDA(i,j,i*5)))
Output
5
5
5
10
10
10
15
15
15
20
20
20
A different approach, but probably not a good one...:
=arrayformula(mround(sequence(12,1,2),3)*(5/3))
try:
=INDEX(FLATTEN(SEQUENCE(4, 1, 5, 5)*SEQUENCE(1, 3, 1, 0)))
or:
=INDEX(FLATTEN(5*MAKEARRAY(4, 3, LAMBDA(x, O ,x))))
I use a Google Spreadsheet to keep track of the accounts payable per vendor. There is a sheet per vendor in the Spreadsheet. A simplified sheet looks like this:
When I receive a new invoice, an entry for the amount is made in the Credit column and when I release a payment, an entry for the amount is made in the Debit column. I keep track of the running total in the AC Payable column. I achieve this by using a formula in each cell of the AC Payable column (the example below is from cell E4):
=IF(
ISNUMBER(INDIRECT(ADDRESS(ROW()-1,COLUMN()))),
INDIRECT(ADDRESS(ROW()-1,COLUMN()))+C4-D4,
C4-D4
)
The logic is simple. The running total for row n is calculated by:
AC Payable(n - 1) + Credit(n) - Debit(n)
This setup works fine, except I have to drag the formula into newly added rows. Is there a way to achieve this by using ARRAYFORMULA?
PS: I have found a solution using:
= ARRAYFORMULA(
SUMIF(
ROW(C3:C),
"<="&ROW(C3:C),
C3:C)
-
SUMIF(
ROW(D3:D),
"<="&ROW(D3:D),
D3:D
)
)
I feel this is a suboptimal (The original sheet dates back to 2018. It has a lot of rows) solution since, in every row, it calculates the total of the Debit and Credit columns up to the current row and then subtracts the total of the Debit column from the total of the Credit column.
I am expecting a solution that would take advantage of the running total available in the previous row and not redo the whole calculation per row.
solution for up to 1581 rows:
=ARRAYFORMULA(QUERY(QUERY(MMULT(TRANSPOSE((SEQUENCE(COUNTA(A3:A)*2)<=
SEQUENCE(1, COUNTA(A3:A)*2))*FLATTEN(INDIRECT("C3:D"&COUNTA(A3:A)+ROW(A3)-1)*{1, -1})),
SEQUENCE(COUNTA(A3:A)*2, 1, 1, 0)), "offset 1", ), "skipping 2", ))
skills:
it's fast
it's smart
gets slower more rows you add
dies after 1581 rows
it's based on standard MMULT Running/Cumulative Total/Sum formula:
=ARRAYFORMULA(MMULT(TRANSPOSE((ROW(B1:B6)
<=TRANSPOSE(ROW(B1:B6)))*B1:B6), SIGN(B1:B6)))
but with a modification twist, because you got 2 columns to total
instead of ROW(B1:B6) we use a sequence of count of real data multiplied by two (because you got 2 columns):
SEQUENCE(COUNTA(A3:A)*2)
instead of TRANSPOSE(ROW(B1:B6)) we use again:
SEQUENCE(1, COUNTA(A3:A)*2)
combination of these pieces:
=ARRAYFORMULA(TRANSPOSE((SEQUENCE(COUNTA(A3:A)*2)<=SEQUENCE(1, COUNTA(A3:A)*2))))
will produce a matrix like:
and that's the reason why it dies with lots of rows because while you may think that if you have only 1500 rows in two columns, then formula will work only on 1500*2=3000 virtual cells, but in fact the MMULT formula processes (1500*2)*(1500*2)=9000000 virtual cells. still, it's worth to note, that this MMULT fx is great if deployed on a small scale.
next, instead of *B1:B6 we use:
*FLATTEN(INDIRECT("C3:D"&COUNTA(A3:A)+ROW(A3)-1)*{1, -1}))
eg. with INDIRECT we take only "valid" range of C3:D which is in your example sheet just C3:D5 and we multiply C column by 1 and D column by -1 to simulate subtraction and then we FLATTEN both columns into one single column. the part +ROW(A3)-1 is just an offset because you start from row 3
and the last part of standard RT fx - SIGN(B1:B6) is replaced with one column full of ones:
SEQUENCE(COUNTA(A3:A)*2, 1, 1, 0)
then we offset the output with inner QUERY by 1 because we are interested in a totals after subtraction and finally we use skipping 2 which means that we filter out every second value - again, we are interested in totals after subtraction of D column.
solution for more than 1581 rows:
=ARRAYFORMULA(
SUMIF(SEQUENCE(COUNTA(A3:A)), "<="&SEQUENCE(COUNTA(A3:A)), INDIRECT("C3:C"&COUNTA(A3:A)))-
SUMIF(SEQUENCE(COUNTA(A3:A)), "<="&SEQUENCE(COUNTA(A3:A)), INDIRECT("D3:D"&COUNTA(A3:A))))
skills:
supports more rows
looks less smart
sadly the third argument of SUMIF always needs to be a range
gets slower with more rows
it will get sick if you feed it with 10000 rows
it may kill off your sheet with 11000+ rows
Here'a modification of Ben Collins' running total formula
=ARRAYFORMULA(
IF(ISBLANK(A2:A),,
MMULT(TRANSPOSE((ROW(C2:C)<=TRANSPOSE(ROW(C2:C)))*C2:C),SIGN(C2:C))-
MMULT(TRANSPOSE((ROW(D2:D)<=TRANSPOSE(ROW(D2:D)))*D2:D),SIGN(D2:D))))
yet another alternative to MMULT:
=INDEX(QUERY(FLATTEN(QUERY(QUERY(TRANSPOSE(QUERY(QUERY(TRANSPOSE(
(SEQUENCE(COUNTA(A3:A)*2)<=SEQUENCE(1, COUNTA(A3:A)*2))*
FLATTEN(INDIRECT("C3:D"&COUNTA(A3:A)+ROW(A3)-1)*{1, -1})),
"offset 1", ), "skipping 2", )), "select "&QUERY(
"sum(Col"&SEQUENCE(COUNTA(A3:A))&"),",, 9^9)&"' '"),
"offset 1", )), "where Col1 is not null", ))
but again, LTE (<=) limitation of 10M cells won't let you use more than 1581 rows in your case or 3162 rows in the standard cumulative sum case
(1581 rows * 2 columns) raised on 2nd power < 10 million cells
(1581*2)^2 = 9998244
I'm trying to make a scoresheet for a competition and I faced a problem when it comes to ranking the competitors.
An example can be found here: https://docs.google.com/spreadsheets/d/1tSiHxGlgNo9oYMypXJ9_ZGrn8O_POQkHspLXhVL9k7M/edit?usp=sharing
The competitors should be ranked by these rules:
Best attempt (higher wins), if this is a tie, then by
Bodyweight (higher wins), if this is also a tie, then by
Second best attempt (higher wins), if this is also a tie, then by
Third best attempt (higher wins), if this is also a tie, then they share a rank
If there no valid attempts (0 in the cell), no rank shall be given
I've been able to get to the 2nd rule (where it compares the bodyweights in case the best attempts are same) but beyond that I'm out of knowledge.
This is what I currently have in cell F2:
=IF(B2=0;"";RANK.EQ($B2; $B$2:$B$10) + COUNTIFS($B$2:$B$10; $B2; $C$2:$C$10; ">" &$C2))
Use weights that differ by order of magnitude with each column, like this:
=arrayformula(
iferror(
rank(
B2:B * 1000000 + C2:C * 10000 + D2:D * 100 + E2:E;
B2:B * 1000000 + C2:C * 10000 + D2:D * 100 + E2:E
)
/
sign(B2:B + D2:D + E2:E)
)
)
This array formula should go to row 2 of a free column. It will fill the whole column in one go.
I have a Google Spreadsheet of numbers. How do I take the maximum value from each column, and summarize them using only one formula? (No temp cells, no scripts.)
1 2 1
0 1 3
0 2 0
For the table above the result should be 6 (1+2+3, the maximum value of each column). But I'd like a solution that works for much larger tables, too.
As a more general question, I'd like to find out how I could fold 2D ranges into 1D arrays using an arbitrary operator (like MAX and SUM in this case).
Assuming your data in range A2:D, to get the maximum of every row (array output) try
=query(transpose(query(if(row(A2:D)>=transpose(row(A2:D)),transpose( A2:D)),"select max(Col1),max(Col2),max(Col3),max(Col4) ",0)),"Select Col2", 0)
If you need to process a lot of columns, this may be better
=ArrayFormula(QUERY(TRANSPOSE(QUERY(TRANSPOSE( A2:D) , "Select "&"MAX(Col"&JOIN( ", MAX(Col",ROW(INDIRECT( "YY1:YY"&ROWS(A2:A)))&")"))), "Select Col2", 0))
To sum, just wrap SUM() around the above formulas.
MAX by columns in A1:C3
=INDEX(QUERY({A1:C3},"Select "&"MAX(Col"&JOIN(", MAX(Col",SEQUENCE(COLUMNS(A1:C3))&")"),0),2)
MAX by rows in A1:C3
=TRANSPOSE(INDEX(QUERY(TRANSPOSE(A1:C3),"Select "&"MAX(Col"&JOIN(", MAX(Col",SEQUENCE(ROWS(A1:C3))&")"),0),2))
Substitute MAX with MIN to get the minimums.