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
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
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)))
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.
how to find a sum of 3 higher values from the range of 6 which are on the one row e.g We have integer values A1:A6 like 2 5 7 4 9 9 It should sum 9+9+7 so 25
Is it possible by any formula or something?
Take a look at the answer Extracting the top five maximum unique values
That should provide you with a basic mechanism (QUERY), to get the top 3 values. Then, apply the SUM function to that result.
So, in your case, you would want:
=SUM(QUERY(A2:A6,"select A order by A desc limit 3",-1))
Here's another one:
=SUM(ARRAY_CONSTRAIN( SORT(A1:A6,1,0),3,1))
Shorter version:
=large(A:A,1)+large(A:A,2)+large(A:A,3)
to apply to an entire column, though A:A could be limited to A1:A6.
I have a Google Sheet with two columns of data. A is monotonically increasing with many duplicates (based on a coarse timestamp), while B is essentially random. There are many empty rows at the bottom waiting for future data. It resembles the following:
A B
1 5 43
2 5 77
3 13 8
4 21 34
5 27 68
6 27 90
7
8
9
10
I'm trying to write a few formulae which examine all of the (non-empty) values in a column except for the last one. For example, I would like to find the maximum value of B excluding the latest value, so the result should be 77 from B2 instead of 90 from B6.
If the values in the range were strictly increasing and unique, I could filter the values of A into C, excluding any values equal to the maximum value (only the last entry), and then take the MAX(..) of that range. However, my data does not have that property; the final value could be duplicated and the duplicates would be inappropriately ignored.
C D E
1 =FILTER(A:A, A:A < MAX(A:A)) =MAX(C:C) This produces A4's 21 instead of A5's 27.
A similar approach would work if we had a third column of incrementing indices to use:
A B C D E
1 5 43 9 =MAX(FILTER(C:C, A:A <> "")) Value of index in last populated row.
2 5 77 10 =MAX(FILTER(A:A, C:C < D1)) Maximum value from a row with lower index.
3 13 8 11
4 21 34 12
5 27 68 13
6 27 90 14
7 15
8 16
9 17
10 18
But I'm looking for a solution that doesn't require modifying the original spreadsheet, because that's not always possible. I can't just create a new IndexSheet with nothing but an an index column and join it in like this instead...
A B C
1 5 43 =MAX(FILTER(IndexSheet!A:A, A:A <> ""))
2 5 77 =MAX(FILTER(A:A, IndexSheet!A:A < C1))
...
...because that requires that the IndexSheet have the same number of rows as the data sheet, and would break as more data is added.
Without modifying the original data sheet, or relying on properties of the data (beyond values being numeric and rows being empty or full), is there any way to perform an aggregate calculation on a range while excluding the last value?
You can use indirect and address formulas to create dynamic range excluding the last row
=max(indirect("A1:"&Address(count(A:A)-1,1)))
The count function gives the number of non empty cells in the column A. You subtract 1 to exclude the last row.
You use that number to build an address using "A1:"&address(row no, Col no) which in your example case should be A1:$A$5
Use this string to reference your cells using the indirect method indirect(A1:$A$5) and pass the reference to the max function to determine the max in that range.
From another sheet try:
=MAX(Sheet1!B1:indirect("Sheet1!B"&count(Sheet1!B:B)-1))
We can use the FILTER() and ROW() functions to accomplish this:
D
1 =MAX(FILTER(Data!A:A,
ROW(Data!A:A) < MAX(FILTER(ROW(Data!A:A),
Data!A:A <> ""))))
We use FILTER(ROW(DATA!A:A), Data!A:A <> "")) to get an array of row numbers of non-empty rows, and use MAX(...) to take the last row number. We use this to exclude the last row by filtering out values from lower row numbers with FILTER(Data!A:A, ROW(Data!A:A) < ...). We apply MAX(...) to this filtered array and get the result we were looking for.