I have this Google Sheets formula that I encountered in this answers here
answer1, answer2, and I couldn't find the support page for it of Google Sheets.
In layman's terms, please explain how this works.
=A5:INDEX(A2:A,COUNTA(A2:A))
Values
Formula
23
36
42
19
12
26
36
10
19
26
10
I was provided with this refrence to this excel's support page by the #TheMaster.
based on your image...
=A5:INDEX(A2:A,COUNTA(A2:A))
is literally translatable as
=A5:A8
where A5: is start of the range INDEX(A2:A is column of the range end, and COUNTA(A2:A) counts how many cells are not empty in range A2:A
formula
transcript
=A5:
=A5:
INDEX(A2:A,
A
COUNTA(A2:A))
8
note that standalone =COUNTA(A2:A) results in 7 but within the formula its 8 due to INDEX being offset
while it is short it is not reliable in case there are empty cells within A2:A range. therefore it is recommended to use:
=A5:INDEX(A:A, MAX((A:A<>"")*ROW(A:A)))
it's a choice of preference but the above is same as:
=INDIRECT("A5:A"&MAX((A:A<>"")*ROW(A:A)))
Related
I have this table in Google Sheets
Month 1 2 3 ...
1 20 30 45
2 32 47
3 53
...
How do I Transpose the last value of each columns into this?
Month lastValue
1 20
2 32
3 53
...
Although I'm not sure whether I could correctly understand your question, in your situation, how about the following sample formula?
Sample formula:
=BYROW(B2:D,LAMBDA(x,IFERROR(INDEX(SPLIT(TEXTJOIN(",",TRUE,x),","),1))))
In this formula, in order to start no empty cell, I used TEXTJOIN and SPLIT. And, the 1st cell is retrieved. I used this with BYROW.
As another approach, this formula =BYROW(B2:D,LAMBDA(x,IFERROR(INDEX(FILTER(x,x<>""),1)))) might be able to be also used.
Testing:
When this formula is used in your provided situation, the following result is obtained.
References:
TEXTJOIN
SPLIT
BYROW
when using the Query function to sort the numbers are out of order. otherwise, the formula is working fine.
It will basically sort as follows;
1
11
12
13
15
15
16
17
18
19
2
20
21
3
4
5
6
7
8
9
Is there a way to get it to sort correctly in numerical order?
Thank you!
First of all, make sure that the format of your data is numerical and not in plain text. You can set the format by highlighting the range of data and apply numerical formatting by using Format > Number > Automatic.
On the other hand, you can use a combination of ARRAYFORMULA within a query formula:
=query({A1:A21,ARRAYFORMULA(A1:A21*1)}, "select Col1 order by Col2")
your input is not numerical. you need to convert it and then it will sorts correctly. now (as you shown in your example) it sorts in alphabetical order
to convert it you can for example multiply your column by 1
In a worksheet of multiple sheets, I have Sheet1, e.g. with the following: (these rows will be less or more and are manually entered)
Sheet1
A B C
1 APPLE ORANGE LEMON
2 bravo chair mars
3 charlie table jupiter
4 alpha box venus
5 delta saturn
6 foxtrot
I would like some help in constructing Sheet2 via formulas so that it rearranges data from Sheet1 as follows
Sheet2 (Desired result)
A B
1 APPLE
2 bravo
3 charlie
4 alpha
5 delta
6 foxtrot
7
8 ORANGE
9 chair
10 table
11 box
12
13 LEMON
14 mars
15 jupiter
16 venus
17 saturn
It probably needs some combination of QUERY() ARRAYFORMULA(), TRANSPOSE() and/or INDEX() but I need some help with getting started and having them into lesser columns (and more rows.) as shown. Please note that Sheet1's data will keep changing in number of rows (or columns) so Sheet2 needs to adapt to that.
Thank you.
You can try following formula:
=ArrayFormula(
{FILTER(
FLATTEN(TRANSPOSE(IF(ROW(A:F)=1;A:F;"")));
FLATTEN(TRANSPOSE(A:F))<>"")
\FILTER(
FLATTEN(TRANSPOSE(IF(ROW(A:F)<>1;A:F;"")));
FLATTEN(TRANSPOSE(A:F))<>"")}
)
if you use semicolon as function argument separator.
If you use comma, change to
=ArrayFormula(
{FILTER(
FLATTEN(TRANSPOSE(IF(ROW(A:F)=1,A:F,""))),
FLATTEN(TRANSPOSE(A:F))<>"")
,FILTER(
FLATTEN(TRANSPOSE(IF(ROW(A:F)<>1,A:F,""))),
FLATTEN(TRANSPOSE(A:F))<>"")}
)
The formula will run faster if you specify a row constraint.
I get massive serialized spreadsheets in the following format:
PN SN Qty
1 24 3
2 25 1
3 26 7
I need to write a Sheets script that can rearrange the data so that the headers are gone, and the quantities are extrapolated, then cleared.
For example, the desired result would be:
1 24
1 24
1 24
2 25
3 26
3 26
3 26
3 26
3 26
3 26
3 26
I have tried writing a few recursive statements to achieve this, however once I started adding in new rows to the sheet my loop breaks. I've tried hundreds of different iterations of what I know should be a fairly simple task but alas, I am well out of practice. I fear at this point I am fixated on the wrong idea. Any help in the right direction would be greatly appreciated!
You don't need to use google apps script.
Try the following formula:
={ARRAYFORMULA(TRIM(TRANSPOSE(SPLIT(QUERY(
REPT(A2:A&"♠", C2:C), ,999^99), "♠")))),ARRAYFORMULA(TRIM(TRANSPOSE(SPLIT(QUERY(
REPT(B2:B&"♠", C2:C), ,999^99), "♠"))))}
Different approach, same result:
=ArrayFormula(SPLIT(QUERY(FLATTEN(SPLIT(FILTER(REPT(A2:A&"\"&B2:B&"^",C2:C),A2:A<>""),"^",0,1)),"Select * Where Col1 <>''"),"\"))
I'm adding this only because different people may find one or the other easier to understand and apply. There is no practical or performance gain to this formula over the great suggestion given by Marios.
NOTE: This formula makes use of an as yet unofficial Google Scripts function, FLATTEN.
I've made an excel document from MS2013 (xlsx) that computes all numbers above it, because i want it to dynamically compute and adjust its own formula as i add more rows above it. But when i import this on google spreadsheets, the formula doesn't work anymore. here is the sample and formula
A B C D
1 3 3 2 2
2 4 3 4 5
3 5 6 4 3
4
5 12 12 10 10
the formula for A5 is =SUM(A1:OFFSET(A5,-1,0))
when i add 1 more row above A5 the formula adjusts accordingly to the formula's current position. What's the correct formula for google spreadsheet?
I propose you this formula (it's certainly not the better solution, nevertheless it's a solution):
=sum(indirect("A1:"&ADDRESS(ROW()-1;COLUMN())))
You can use this in your example:
=SUM(A1:A4)
If you start adding extra rows, then they will be automatically accounted for.