In Sheets I would like fixed sequence of 1-12. I have set it as =sequence(3,4) and I would like it to roll and wrap when I change the first number
Apologies in advance for formatting. I would like the array to roll and wrap when I change the first number in the sequence. So, the starting array is 1-12, but when I change the first number to 4 I would like the sequence to run from there and wrap around back to 1.
1 2 3 4
5 6 7 8
9 10 11 12
But if I start at 4 I would like it to read
4 5 6 7
8 9 10 11
12 1 2 3
Say your start number is in A1:
=ArrayFormula(MOD(SEQUENCE(3,4,A1-1,1),12)+1)
This uses MOD to cycle through the sequence.
Related
Using this table:
A
B
C
D
1
2
3
4
5
6
7
8
9
10
11
12
In Google Sheets if I do this here in column E:
={A1:B3;C1:D3}
Teremos:
E
F
1
2
5
6
9
10
3
4
7
8
11
12
But the result I want is this:
E
F
1
2
3
4
5
6
7
8
9
10
11
12
I tried multiple options with FLATTEN, but none of them returned what I wanted.
Well you can try:
=WRAPROWS(TOCOL(A1:D3),2)
You could try with MAKEARRAY
=MAKEARRAY(ROWS(A1:D3)*2,2,LAMBDA(r,c,INDEX(FLATTEN(A1:D3),c+(r-1)*2)))
GENERAL ANSWER
For you or anyone else: to do something similar but with a variable number of columns of origin or of destination, you can use this formula. Changing the range and amount of columns at the end of LAMBDA:
=LAMBDA(range,cols,MAKEARRAY(ROWS(range)*ROUNDUP(COLUMNS(range)/cols),cols,LAMBDA(r,c,IFERROR(INDEX(FLATTEN(range),c+(r-1)*cols)))))(A1:D3,2)
you can do:
={FLATTEN({A1:A3, C1:C3}), FLATTEN({B1:B3, D1:D3})}
for more columns, it could be automated with MOD
I've got these 3 groups of data in range F2:G22 as below
(3 groups as minimal example, in reality many thousands of groups, and recurrent similar datasets expected in the future):
I need to number each group's rows sequentially, starting over at 1 at each new group.
The expected result would be like in range E1:E22.
I tried the following formula n cell C2 , then in cell D3:
=INDEX(IF(A2:A22="",COUNTIFS(B2:B22&A2:A22, B2:B22&A2:A22, ROW(B2:B22), "<="&ROW(B2:B22)),1))
In C2:
In D3:
That fixed partially the sequence issue, but there's still 2 issues I can't find remedy for.
1st remaining issue:
I'd prefer not having to manually do the C2 to D3 step each time I get new similar data (but would accomodate if there's no simple solution to this issue).
Is there a simple way to modify the formula to make it output the correct sequencing from C2 ?
2nd remaining issue:
At rows 7, 14 and 23 there still remain unecessary ending numbering for these intermediary rows in D7 , D14 , and D23:
I could only think of an extra manual step of filtering out the non-blank rows in Column A to fix this 2nd issue (i.e. Highlighting Column A > Data tab > Create Filter > Untick all > Tick Blanks > Copy All > Paste In new Sheet).
But would there be a way to do it in the same formula? I'm not seeing the way to add the proper filter or using another method in the formula.
Any help is greatly appreciated.
EDIT (Sorry for Forgotten Sample):
Formula Input A
Formula Input B
Formula Output 1
Formula Output 2
EXPECTED RESULT
rockinfreakshow
ztiaa
DATA
DATA BY GROUP
7
1
1
7
7
2
1
1
1
2
Element-1
Group-1
7
3
2
2
2
3
Element-2
Group-1
7
4
3
3
3
4
Element-3
Group-1
7
5
4
4
4
5
Element-4
Group-1
8
1
5
6
8
8
2
1
1
1
7
Element-1
Group-2
8
3
2
2
2
8
Element-2
Group-2
8
4
3
3
3
9
Element-3
Group-2
8
5
4
4
4
10
Element-4
Group-2
8
6
5
5
5
11
Element-5
Group-2
8
7
6
6
6
12
Element-6
Group-2
9
1
7
13
9
9
2
1
1
1
14
Element-1
Group-3
9
3
2
2
2
15
Element-2
Group-3
9
4
3
3
3
16
Element-3
Group-3
9
5
4
4
4
17
Element-4
Group-3
9
6
5
5
5
18
Element-5
Group-3
9
7
6
6
6
19
Element-6
Group-3
9
8
7
7
7
20
Element-7
Group-3
9
9
8
8
8
21
Element-8
Group-3
9
Can you try:
=INDEX(LAMBDA(y,z,
IF(LEN(z),COUNTIFS(y,y,ROW(z),"<="&ROW(z)),))
(LOOKUP(ROW(G2:G),FILTER(ROW(G2:G),BYROW(G2:G,LAMBDA(z,IF(z<>OFFSET(z,-1,0),row(z),0))))),G2:G))
You can simply use SCAN.
=SCAN(,G2:G,LAMBDA(a,c,IF(c="",,a+1)))
Sample sheet
I have three Arrayfire arrays that look like this:
Array 1 Array 2 Array 3
20 5 9
3 0 0
9 4 8
0 20 22
... ... ...
Using Arrayfire, I would like to generate 2 new arrays. The first should contain values from Array 1. Each value should be repeated a number of times dictated by the interval between the corresponding values in Array 2 (inclusive) and Array 3 (exclusive). The second array should contain an expansion of the values within each interval for each value from Array 1. Sorry if that's not clear. Here's the desired output to hopefully clarify:
Array 1 Array 2
20 5
20 6
20 7
20 8
9 4
9 5
9 6
9 7
0 20
0 21
... ...
The order of the output doesn't matter.
Thanks, in advance, from an Arrayfire novice.
I have a data in "A" column like as below starting from A2 cell.
7cz2
6789efg
abc890
34l1
78kk
88
63
What I need is
7
2
6
7
8
9
8
9
0
3
4
7
8
8
8
6
3.
I do have applied =VALUE(REGEXREPLACE(A2,"\D+", "")) but is is giving me data like
72
6789
890
34
78.
Is there a way to solve this.Thanks in advance.
Use 2 formulas.
join and replace letters in cell C1:
=REGEXREPLACE(JOIN("",A1:A7),"[A-Za-z]","")
split by symbol:
=TRANSPOSE(REGEXEXTRACT(C1,REPT("(.)",LEN(C1))))
The result:
Currently I have a scope that pulls back my records in the following standard order:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
and it is converted in to a html block that's laid out as so:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
I want a html block that's laid out like so:
1 6 11 16
2 7 12
3 8 13
4 9 14
5 10 15
So I think I need to pull the records back in the following order - (records offset by the number of rows)
1 6 11 16 2 7 12 3 8 13 4 9 14 5 10 15
Any idea what is the neatest way to do this in Rails / ActiveRecord?
You must know how many columns you want to eventually render. I think this must work for you:
columns = 5
MyModel.order(:id).in_groups_of(columns).transpose
And you get an array of lines, each one with an array of records.
If you want an unique array you can add .flatten at the end.
Can't do that with AR ordering! You will have to do that in your controller or the view.