horizontal alternative columns with transpose - google-sheets

Transposing rows in alternate columns
Suppose I have a continuous row
A1 = 1 A2 = 2 A3 = 3 A4 = $
I need to transpose it to
B1 = 1 D1 = 2 F1 = 3 H1 = 4
Is it possible?

=TRANSPOSE({A1; ""; A2; ""; A3; ""; A4})

={A1, "", A2, "", A3, "", A4}
if you are not US localized use: ={A1\ ""\ A2\ ""\ A3\ ""\ A4}

Try:
=if(isodd(column()),"",OFFSET($A1,int(column()-2)/2,))
in B1 and copy across to the right (assuming LTR).

Related

Fill formula from other sheet horizontally

Set-up
I have 2 Google Sheets tabs; Vertical and Horizontal.
Data in Vertical is noted vertically, that is,
A1 = X
A2 = Y
A3 = Z
etc.
I want the data from Vertical horizontally in Horizontal, that is
A1 = Vertical!A1 = X
B1 = Vertical!A2 = Y
C1 = Vertical!A3 = X
etc.
Isssue
When I set A1 = Vertical!A1 and drag the field horizontally to fill B1, C1,... I get,
A1 = Vertical!A1 = X
B1 = Vertical!B1 = empty
C1 = Vertical!C1 = empty
etc.
that is, instead of incrementing the number, Sheets increments the letter.
Question
How do I get Sheets to increment the number instead of the letter?
Simply copy+paste special -> transpose doesn't work between 2 sheets, it seems.
Googling around I see a lot of fancy formulas that don't do what they say?
Tried:
https://stackoverflow.com/a/30003770/7326714
https://webapps.stackexchange.com/a/126830
https://webapps.stackexchange.com/a/126844
use this and drag to the right:
=INDIRECT("Vertical!A"&COLUMN(A1))
you can use TRANSPOSE
=TRANSPOSE(vertical!A:A)
Transpose auto fill the others cells so there is no need to drag

Calculate Pivot D1 W1 M1

How can I calculate the Pivots D1, W1 and M1?
Can you provide me some ready to use formula?
It depends on the type of Pivot of course. The easiest, standard pivot should look like this one: high,low,close are High(_Symbol,PERIOD_D1,1) etc.
double values[] is a buffer of 9 pivot values
double p = (high+low+close)/3;
values[0+4] = p;
values[1+4] = 2*p-low;
values[2+4] = p+high-low;
values[3+4] = 2*p+high-2*low;
values[4+4] = 2*p-high;
values[5+4] = p+low-high;
values[6+4] = 2*p+low-2*high;
values[7+4] = p + 2 * (high-low);
values[8+4] = p - 2 * (high-low);

Pairs in lua programming

I have two set of values defined:
local A1 = {100, 200, 300, 400}
local A2 = {500, 600, 700, 800}
I want to iterate a loop assigning values for another variable B1 and B2 as pairs from A1 and A2 as follows:
B1 = 100 and B2 = 500 (first iteration)
B1 =200 and B2 = 600 (second iteration)
B1 = 300 and B2 = 700 (third iteration)
B1=400 and B2 = 800 (fourth iteration)
I tried to use ipairs as follows:
for i, f1 in ipairs(A1) do
for j, f2 in ipairs(A2) do
B1 = f1
B2 = f2
end
end
but this gave me
B1 = 100 and B2 = 500 (first iteration)
B1 =100 and B2 = 600 (second iteration)
B1 = 100 and B2 = 700 (third iteration)
B1=100 and B2 = 800 (fourth iteration)
B1 = 200 and B2 = 500 (fifth iteration)
B1 =200 and B2 = 600 (sixth iteration)
B1 =200 and B2 = 700 (seventh iteration)
....
...
...
so on...
can anyone help me to code in the right way?
You can easily do this with a numerical loop:
for i = 1, 4 do
local a, b = A1[i], B1[i]
--- use them
end
How you go about determining the number of iterations you'll need is the tricky part. If the sizes are variant, but each table is the same length as the others you can instead use the length operator (#A1).
Alternatively, you might want a function that returns the largest length of a given set of tables.
local function max_table_len (...)
local tabs = { ... }
local len = 0
for i = 1, #tabs do
local l = #tabs[i]
if l > len then
len = l
end
end
return len
end
And maybe even a helper function to get each value.
local function get_from_tables (index, ...)
local values = { ... }
local len = #values
for i = 1, len do
values[i] = values[i][index]
end
return table.unpack(values, 1, len)
end
Ending up with something like:
for index = 1, max_table_len(A1, B1) do
local a, b = get_from_tables(index, A1, B1)
end
You can build on the ipairs example from Programming in Lua. For instance this version iterates over 2 sequences in parallel:
-- iterator function
local function iter_ipairs2(tablePair, i)
i = i + 1
local v1 = tablePair[1][i]
local v2 = tablePair[2][i]
-- if you use 'and' here the iteration stops after finishing
-- the shortest sequence. If you use 'or' the iteration
-- will stop after it finishes the longest sequence.
if v1 and v2 then
return i, v1, v2
end
end
-- this is the function you'll call from your other code:
local function ipairs2(t1, t2)
return iter_ipairs2, {t1, t2}, 0
end
-- usage:
local A1 = {100, 200, 300, 400, 500}
local A2 = {500, 600, 700, 800}
for i, v1, v2 in ipairs2(A1, A2) do
print(i, v1, v2)
end
The previous answers are more detailed and provide a more general and better answer.
This one is for someone very new to Lua. Not only does it show two loops, it reinforces that there is usually more than one way to get where you want to go.
local A1 = {100, 200, 300, 400}
local A2 = {500, 600, 700, 800}
print("simplest answer:")
-- doesn't use ipairs and assumes A1 and A2 are the same size
for i = 1, #A1 do
B1 = A1[i]
B2 = A2[i]
print(B1, B2, "(iteration #"..i..")")
end
print()
print("answer that uses ipairs:")
-- again, assumes A1 and A2 are the same size
for i, v in ipairs(A1) do
B1 = A1[i] -- i steps through A1 and A2
B2 = A2[i] -- this works because A1 and A2 are same size
print(B1, B2, "(iteration #"..i..")")
end
Gives this output:
simplest answer:
100 500 (iteration #1)
200 600 (iteration #2)
300 700 (iteration #3)
400 800 (iteration #4)
answer that uses ipairs:
100 500 (iteration #1)
200 600 (iteration #2)
300 700 (iteration #3)
400 800 (iteration #4)

Score calculation for two different teams

How would i go about counting the scores between C1 and C8 and entering the values into A2 and B2?
a1 = blue
b1 = red
a2 = team blue score
b2 = team red score
between c1 to c8 = winning team & score (NOTE: c1 = $a$1&" 1.25" )
c1 = blue 1.25
c2 = blue 2
c3 = red .5
c4 = draw
c5 = blue 1.5
c6 = blue 1.75
c7 = red 2
c8 = draw
So what I should get is:
A2 should = 6.5
B2 should = 2.5
You can get the total score of the blue team with
=sum(arrayformula(if(left(C1:C, 4)="blue", value(regexreplace(C1:C, "[^0-9.]", "")), 0)))
For the red team, use left(C1:C, 3)="red" in the formula.
The conversion from text to number happens in two steps: regexreplace removes all characters except . and 0-9; then value converts text to number.
It would be better to keep the winning team and their score in separate cells (team in column C, their score in column D), which would simplify the handling of this data: you'd only need =sumif(C1:C, "blue", D1:D).
Taking help of helper columns and without Array formula.These formula can adapt if you change team to Green or any other colour.
Formula in D1:(And Fill down)
=VALUE(RIGHT(C1,(LEN(C1)-LEN($A$1))))
Formula in E1:((And Fill down)
=LEFT(C1,(MIN(FIND({0,1,2,3,4,5,6,7,8,9},C1&"0123456789"))-2))
(And Fill down)
Formula in A2:
=SUMIF(E1:E9,"blue",D1:D9)
Formula in B2:
=SUMIF(E1:E9,"red",D1:D9)

How to convert datetime interval to hours?

I have this spreadsheet:
A B C D E
1 08/13/2013 02:10 4
2 08/13/2013 02:19 10 00:09:00 160
In D2, I have this formula : =if(B2="";"";to_date(concatenate(A2;" ";B2))-to_date(concatenate(A1;" ";B1)))
In E2 I have this formula : =if(D2="";"";(C2-C1)/D2)
But E2 outputs the wrong result, 160. I want it to be 40 (=10-4/0.15). 0.15 is the value in D2 converted to hours.
How can I do that?
Do not quite understand what you're trying to calculate, but with the information that explains, the following formula can help:
=IF(D2 = "", "", ROUND((C2-C1)/(D2*24), 0))

Resources