Google sheets Array split function formula - google-sheets

I have this Google sheet:
I am using this formula to split my strings in columns
=ARRAYFORMULA(IFERROR(IF(D2:D=1, SPLIT(A2:A, "+"), SPLIT(C2:C, "+"))))
Molecules ID NAME Vitamin_in_name NAME1 NAME2 NAME3
VITAMIN B1 + VITAMIN B6 + VITAMIN B12 1 VITAMIN B1,B6,B12 1 VITAMIN B1 VITAMIN B6 VITAMIN B12
2 LIDOCAINE + VITAMIN B4,B8,B10 1
3 SALICYLIC ACID + TALC 0 SALICYLIC ACID TALC
I would like to return this sheet. IF the word "vitamin_in_name" = 1 and "molecules" row is empty to re-format the data like in ID2 Column name1, name2, name3. how can i do modify my array formula to do that?
Molecules ID NAME Vitamin_in_name NAME1 NAME2 NAME3 NAME4
VITAMIN B1 + VITAMIN B6 + VITAMIN B12 1 VITAMIN B1,B6,B12 1 VITAMIN B1 VITAMIN B6 VITAMIN B12
2 LIDOCAINE + VITAMIN B4,B8,B10 1 LIDOCAINE VITAMIN B4 VITAMIN B8 VITAMIN B10
3 SALICYLIC ACID + TALC 0 SALICYLIC ACID TALC

Your request is a bit ambiguous, since you didn't specify what should happen if both these conditions are true:
Molecules column is not blank.
Vitamin_in_name is not 1.
I assumed that, in this case, the values should come from column C, and so Vitamin_in_name is not really needed for this.
In any case, I would do the following:
Check if column A is blank with ISBLANK.
If column A is blank then (1) use REGEXREPLACE to replace all , from column C with +VITAMIN, and (2) SPLIT using + as separator.
If column A is not blank, use a simple SPLIT on column A, with + as separator.
The resulting formula could be this:
=ARRAYFORMULA(IFERROR(IF(ISBLANK(A2:A),SPLIT(REGEXREPLACE(C2:C,",","+VITAMIN "),"+"),SPLIT(A2:A,"+"))))

Related

google sheet - propagate a MAXIF function whitin a column

I have a table in a first sheet called 'Ansewers to form' with :
Date
Name
First_Name
18/01/2023 14:44:18
Name1
FName1
18/01/2023 14:46:24
Name1
FName1
18/01/2023 16:37:30
Name2
FName2
18/01/2023 16:47:12
Name1
FName1
18/01/2023 16:47:35
Name3
FName3
And a second table called 'sheet1':
Date
Name
First_Name
18/01/2023 16:47:12
Name1
FName1
_
Name2
FName2
_
Name3
Fname3
I would like to recover the latest connection of each Name/Fname.
So I the cell A2 of sheet1 I have this formula :
=MAXIFS('Answers to form'!A2:A;'Answers to form'!B2:B;B2;'Answers to form'!C2:C;C2)
I would like to propagate the formula (just like with arrayformula); meaning that in A3 you have
=MAXIFS('Answers to form'!A2:A;'Answers to form'!B2:B;B3;'Answers to form'!C2:C;C3), and so...
Any idea ?
In Google Sheets you might lock a column or row with $.
In your case
=MAXIFS('Answers to form'!$A$2:$A;'Answers to form'!$B$2:$B;$B2;'Answers to form'!$C$2:$C;$C2)
Will drag on second line (which is line 3) to
=MAXIFS('Answers to form'!$A$2:$A;'Answers to form'!$B$2:$B;$B3;'Answers to form'!$C$2:$C;$C3)

QUERY in ARRAYFORMULA to FILTER, JOIN and LEN

Given a table like this one:
A
B
C
D
E
1
Tese
(2021/039-07964)
(8146.000336/2021-60)
Tema 1092
2
Afetado
Tema 1092
Controvérsia 251
|3|Tese|(2021/0390796-6)||Tema 1093|Controvérsia 258|
|4|Afetado|||Tema 1093|Controvérsia 258|
|5|Tese|(2021/0390796-7)|(8146.000338/2021-50)||Controvérsia 238|
As long strings in Col A's rows are equal to "Tese", Col F should return a string (with line breaks) that compiles Col B to D strings that are not null in the same row.
So, row 1 of Col F should be:
F
(2021/0390796-4)(8146.000336/2021-60)Tema 1092
Row 2 of Col F should be:
F
(2021/039-07966)Tema 1093Controvérsia 258
And so on
I'm using a dropdown formula to do the job, which is working fine:
=IFERROR(IF(A1="Tese",JOIN(CHAR(10),FILTER(B1:E1, LEN(B1:E1))),""))
But it would be easier if it could be replaced by an array formula (the table is over 4,000 rows!).
I think it is possible to use a query, but I could not write the formula down.
The real table is here: link
Clear all contents of column G and try in G1
={"Informações completa da tese"; INDEX(IF(A2:A="Tese"; SUBSTITUTE(SUBSTITUTE(TRIM(TRANSPOSE(QUERY(TRANSPOSE(SUBSTITUTE(B2:F; " "; "$"));;ROWS(A2:A)))); " "; char(10)); "$"; " ");))}
See if that helps?

Google sheet -> filtering a query

I created the following sheet:
https://docs.google.com/spreadsheets/d/1AJmzlBlrDZ0mfb_9aSm83fzZxrwYWOxWGxjNhlfqPLA/edit?usp=sharing
I am trying to find a formula to calculate the totals (C7, C8, C9) and wherever it is copied ie C17, C18, C19)
So for C7 I want to sum column D (Duration) wherever:
the Date (col A) is the same as the total row date (that is A7)
The Category (col E) is Internal
Similarly for So for C8 I want to sum column D (Duration) wherever:
the Date (col A) is the same as the total row date (that is A8)
The Category (col E) is External
and
for C9 I want to sum column D (Duration) wherever:
the Date (col A) is the same as the total row date (that is A9)
Has any category
I tried for C7 -
=QUERY({A:E, arrayformula(N(D:D))}, "select sum(Col6) where Col5='Internal' and Col1 = " & A7 & " label sum(Col6) ''",1)
but I get NA ??? any help ?
-
I wouldn't complicate life with a QUERY() here. Instead, just use FILTER().
Total Internal: =SUM(FILTER(D:D, A:A=A7, E:E="Internal"))
Total External: =SUM(FILTER(D:D, A:A=A8, E:E="External"))
Total All: =SUM(FILTER(D:D, A:A=A9))

Google Spreadsheet, operations with above row cell in same column with arrayformula

I have arrayformula in the first row of a column so my values and calculations can start in Row 2 and for all the column length.
I have this situation:
https://docs.google.com/spreadsheets/d/11oDra7Vja4-5C0Uix7JTgLLSMG3gPj-6fkajXlWqqQk/edit?usp=sharing
I need a simply arithmetic operation:
Subtract above value of the same column for every row.
I'm using:
=arrayformula(IF(row(A:A)=1; "What I have now"; IF(ISBLANK(A:A); ""; A1:A-A2:A)))
but as you see is wrong.
How to do that?
UPDATED QUESTION:
And then in the second sheet I need a SUM operation with some blank cells in column:
How to do that?
https://docs.google.com/spreadsheets/d/11oDra7Vja4-5C0Uix7JTgLLSMG3gPj-6fkajXlWqqQk/edit#gid=931743679
If you want to have the array formula ion the header this is a bit weird as you need to allow the formula to technically access row 0, we can do this by constructing ranges.
=ArrayFormula(IF(
--(ROW(A1:A) > 2) + -ISBLANK(A1:A) = 1;
{0; A1:A} - {0; A2:A; 0};
""))
--(ROW(A1:A) > 2) + -ISBLANK(A1:A) = 1 Checks if the row is populated and not one of the first two rows in a way that works nicely with array formulas
{0; A1:A} - {0; A2:A; 0} does the following:
0 Data 156 123 110 95 42
- - - - - - -
0 156 123 110 95 42 0
= = = = = = =
0 33 13 15 53 42 42
N N Y Y Y Y N <- Is shown
^ ^ ^
| | Because Row is blank
| |
Because row not > 2, thus it is never evalauated even though the second would cause an error
I think this is quite tricky. The problem is that in an array formula the number of cells in each array must match - you can't mix an array starting in row 1 with an array starting in row 2 if they go all the way to the bottom of the spreadsheet.
Here is one way of getting the result you want
=arrayformula({"What I need";"";offset($A$1,1,0,count(A:A)-1)-offset($A$1,2,0,count(A:A)-1)})
You will need to change the ; and , for your locale.
I have built up an array using the {} notation to define the elements. In my locale a ; means go to the next row, so I have defined the first two cells directly as strings. After that I've chosen to use Offset to get the range A2:A5 (1 row down from A1, 0 rows across and 4 cells high) and subtract the range A3:A6 (2 rows down from A1, 0 rows across and 4 cells high) it so that gives me the other 4 cells.
B1 "What I need"
B2 ""
B3 A3-A2=33
B4 A4-A3=13
B5 A5-A4=15
B6 A6-A5=53
but will need an IF statement adding if there are any blank cells between the numbers.
In the particular case of your updated question where there are fewer numbers in column D than column C, the formula would be
=arrayformula({"Special Case";"";offset($D$1,1,0,count(D:D))+offset($C$1,2,0,count(D:D))})
But in the general case of there being blank cells anywhere, you would have to test everything
=arrayformula({"General Case";"";if(offset($D$1,1,0,rows(C:C)-2)="","",if(offset($C$1,2,0,Rows(C:C)-2)="","",offset($D$1,1,0,rows(C:C)-2)+offset($C$1,2,0,Rows(C:C)-2)))})

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