Add variable text (sequential small letters) to query results - google-sheets

I'm getting strings like the following at Col B on Page3 of this sheet:
) Reason1, Name: Bruno (2º OfSC, 3844923); ) Reason1, Name:
Wladimir (3º OfSC, 3693237); ) Reason2, Name: Jorge (9º OfSC,
4715814); ) Reason3, Name: Holden (1º OfSC, 4541195); )
Reason4, Name: John (5º OfSC, 4729589); ) Reason5, Name: Antony
(6º OfSC); ) Reason5, Name: Edson (7º OfSC);
Is there a way to use CHAR(ROW(97)) or lower(regexreplace(address(1,row(A1)),"[^A-Z]","")) into the formula =IFERROR( TEXTJOIN( CHAR(10); TRUE; TRANSPOSE( QUERY(Page2!$A$3:$C; "select C where A <= date '" & TEXT( DATEVALUE(A4); "yyyy-mm-dd") & "' and (B >= date '" & TEXT( DATEVALUE(A4); "yyyy-mm-dd") & "' or B is null)")))) to get the following result?
a) Reason1, Name: Bruno (2º OfSC, 3844923); b) Reason1, Name:
Wladimir (3º OfSC, 3693237); c) Reason2, Name: Jorge (9º OfSC,
4715814); d) Reason3, Name: Holden (1º OfSC, 4541195); e)
Reason4, Name: John (5º OfSC, 4729589); f) Reason5, Name: Antony
(6º OfSC); g) Reason5, Name: Edson (7º OfSC);
I have unsuccessful tried = TEXTJOIN( CHAR(10); TRUE; TRANSPOSE( ARRAYFORMULA QUERY({CHAR(ROW(97)&Page2!$A$3:$C}; "select C where A <= date '" & TEXT( DATEVALUE(A4); "yyyy-mm-dd") & "' and (B >= date '" & TEXT( DATEVALUE(A4); "yyyy-mm-dd") & "' or B is null)"))) on Page3's Col C
Also, it would be great if the formula could be an array!

If you take a look at your sample sheet there is a new tab called MK.Idea.
In it you will find this formula in cell I1:
=ARRAYFORMULA(QUERY(IFERROR(SPLIT(FLATTEN(Page1!E3:E70&", Name:"&Page1!C3:C70&" ("&Page1!D3:D70&IF(LEN(Page1!F3:F70);", "&Page1!F3:F70;)&")|"&Page1!A3:A70+SEQUENCE(1;L2;0)&"|"&TEXT(Page1!A3:A70+SEQUENCE(1;L2;0);"mmmyyyy")&"|"&(1*SUBSTITUTE(Page1!B3:B70;"undefined";TODAY())));"|";0;0));"select Col2,Col1 where Col2<=Col4 and Col3 = "&DATE(A1;A2;1)&" order by Col2 label Col2'Date',Col1'Reason'"))
Which does all of the work directly from the Page1 tab. It does not use anything besides the original data. So Page2 and Page 3 are not necessary.
This formula supplies dynamic dates:
={"Date";SEQUENCE(DAY(EOMONTH(DATE(A1;A2;1);0));1;DATE(A1;A2;1))}
Then an "Filter" type formula built as an arrayformula gets the result.
={"Reasons";ARRAYFORMULA(VLOOKUP(A4:A34;SPLIT(TRANSPOSE(SUBSTITUTE(TRIM(QUERY(QUERY({F:F&"|"\CHAR(10)&H:H&G:G};"select MAX(Col2) group by Col2 pivot Col1");;9^9));" "&CHAR(10);";"&CHAR(10)));"|;"&CHAR(10);0);2;0))}
Here, a copy of the OP's sheet with my solution will live in perpetuity.

Related

Index and Concat / Concatenate from another sheet

I have a data sheet which i want to index pull into another sheet and also concanate or concat 2 or more columns with array formula.
sheet link here
https://docs.google.com/spreadsheets/d/1GUI-Gl7HDNGg5V2wM4ossUn46cp7VHRBZ_t4la2gDH0/edit?usp=sharing
data sheet https://docs.google.com/spreadsheets/d/1GUI-Gl7HDNGg5V2wM4ossUn46cp7VHRBZ_t4la2gDH0/edit#gid=0
result required sample sheet https://docs.google.com/spreadsheets/d/1GUI-Gl7HDNGg5V2wM4ossUn46cp7VHRBZ_t4la2gDH0/edit#gid=1226812843
you can see in result sheet column B and F which are merged from "data sheet column b c d and h i simultaneously"
Use an { array expression }. Insert > Sheet and put this formula in cell A1 of the new sheet:
=arrayformula(
{
DATA!A1:A,
trim(
DATA!B1:B & " " &
if( iserror(search(DATA!C1:C, DATA!B1:B)), DATA!C1:C, "" ) & " " &
if( iserror(search(DATA!D1:D, DATA!B1:B)), DATA!D1:D, "" )
),
DATA!E1:G,
trim(DATA!H1:H & if(len(DATA!I1:I), " / " & DATA!I1:I, "")),
DATA!J1:U
}
)
The formula will only append the values in columns C and D to the value in column B when they do not not already appear in the value in column B.
the prior answer is ok but did you know...
so your issue can be solved as:
=BYROW(DATA!A2:INDEX(DATA!A:A, COUNTA(DATA!A:A)),
LAMBDA(a, {a, TEXTJOIN(" ", 1, OFFSET(a,,1,,3)), OFFSET(a,,4,,3),
TEXTJOIN(" / ", 1, OFFSET(a,,7,,2)), OFFSET(a,,9,,11)}))

Count current and longest streak from null or 1 values

I'm trying to count longest and current streak from null or 1 values in google sheets.
It's going to be used in Data Studio, but I have to make calculation in Sheets.
I've tried a sultion from below post, but it's nor working for me and also I have null values not 0, and it has to stay this way (rows in sheet are being appended from google forms form, where I check whether I did a habit or not).
Google Sheets - How to count streaks of non-zero numbers on one column
Please help if you can, thanks before
Here is the spreadsheet with some example data
https://docs.google.com/spreadsheets/d/1GaaEJ24ERulPftYAILOuokY929HInkh-SjAJUEvrW5M/edit?usp=sharing
values to visualize in streaks
Use this to get the longest streak in data:
=arrayformula(
if(
len(join(""; Data!A1:A));
max( len( split(
concatenate( left(isblank(Data!A1:A)) );
"T"
) ) );
"no streak"
)
)
And this to get the last streak in the data:
=+sort(
if(
len(join(""; Data!A1:A));
len( transpose( split(
concatenate( left(isblank(Data!A1:A)) );
"T"
) ) );
"no streak"
);
sequence( rows(
transpose( split(
concatenate( left(isblank(Data!A1:A)) );
"T"
) )
) );
false
)
See your sample spreadsheet.
longest:
=INDEX(COLUMNS(SPLIT(FLATTEN(SPLIT(TRIM(QUERY(IF(A1:A=""; 0; "×");;9^9)); " 0 "; )); " ")))
all:
=INDEX(QUERY(LEN(SUBSTITUTE(FLATTEN(TRIM(SPLIT(QUERY(
IF(A1:A=""; "×"; "¤");;9^9); "×"; ))); " "; ));
"where Col1 <> 0"))
last:
=INDEX(QUERY(SORT(LEN(SUBSTITUTE(FLATTEN(TRIM(SPLIT(QUERY(
IF(A1:A=""; "×"; "¤");;9^9); "×"; ))); " "; ));
SEQUENCE(ROWS(A1:A)-COUNTA(A1:A)); 0); "where Col1 <> 0 limit 1"; ))

Concatenate columns while avoiding blanks and duplicates

Trying to combine range E4:I into J4:J with the Array Formula of:
=ArrayFormula( regexreplace( regexreplace( transpose( trim( query( transpose( regexreplace( trim( E4:I ) , " " , "~" ) ) ,, 9^99 ) ) ) , " " , ", " ) , "~" , " " ) )
This formula works well but I want to exclude duplicates in each row.
Here is a link to the sheet. Link
You can try this modified formula from a similar post:
=INDEX(
REGEXREPLACE(SORT(
SPLIT(
TRANSPOSE(QUERY(
QUERY(
UNIQUE(
SPLIT(
FLATTEN(
ROW(E2:I11) & "♦♥" & E2:I11
), "♥"
) & ", "
),
"SELECT MAX(Col2)
WHERE Col2 IS NOT NULL
GROUP BY Col2
PIVOT Col1",
),,99
)),"♦"
), 1, TRUE),
"^(?:,\s*)+|(?:,\s*)+$|(,\s)\s*(?:,\s*)*",
"$1"
),,2)
Output:
Note:
Output is automatically sorted alphabetically
You can change E2:I11 to E2:I but it will be slower than limiting your range. If you have a column that can identify until what row is populated, add an IF statement and limit your formula to only process those rows.
Reference:
https://stackoverflow.com/a/67837006/17842569

Convert multi column data in a single row that contains delimiter, to a multi row and flatten delimiter so only one item is in each cell

I am looking to split, and flatten, with an array formula, and keep the correct corresponding Reference Number, assigned to multiple rows of flattened data.
Column A: Reference Number
Column B: ID (CSV)
Column C: TEMP ID (CSV)
Current Format
| A | B | C |
|111|001 002 | |
|222|004 005 006 008| |
|333|007 |T001 T006 T002|
|888| |T005 T004 T008|
|444| |T007 |
Expected Results
| A | B | C |
|111|001| |
|111|006| |
|222|004| |
|222|005| |
|222|006| |
|222|008| |
|333|007| |
|333| |T001|
|333| |T006|
|333| |T002|
|888| |T005|
|888| |T004|
|888| |T008|
|444| |T007|
Here is another post which is similar to what I am looking to accomplish.
(The only difference is in this post, the OP only had 2 columns.)
Here is the formula that I'm using (Not working perfectly):
=ARRAYFORMULA(TRIM(QUERY(SPLIT(FLATTEN(IF(IFERROR(SPLIT('Form Responses'!C2:D, " "))="",,
'Form Responses'!B2:B&"×"&SPLIT('Form Responses'!C2:D, " "))), "×"), "where Col2 is not null")))
What am I doing wrong?
Here is my sheet.
Use this:
=arrayformula(
regexreplace(
text(
split(
query(
flatten( iferror( 'Form Responses'!B2:B & "µ" & iferror(split('Form Responses'!C2:C, " ")) & "µ" & iferror(split('Form Responses'!D2:D, " ")) ) ),
"where Col1 is not null and not Col1 ends with 'µµ' ",
0
),
"µ", false, false
),
"000"
),
"000", ""
)
)
Note that this formula will produce a row that looks like this:
Reference
#ID
Temp ID
333
007
T001
I.e., source data rows that have both an ID and a Temp ID will share a reference number. To make these IDs go to their own rows, use this:
=arrayformula(
regexreplace(
text(
split(
{
query(
flatten( iferror( 'Form Responses'!B2:B & "µ" & iferror(split('Form Responses'!C2:C, " ")) & "µ" ) ),
"where Col1 is not null and not Col1 ends with 'µµ' ",
0
);
query(
flatten( iferror( 'Form Responses'!B2:B & "µµ" & iferror(split('Form Responses'!D2:D, " ")) ) ),
"where Col1 is not null and not Col1 ends with 'µ' ",
0
)
},
"µ", false, false
),
"000"
),
"000", ""
)
)
The result table will have all the ID rows first, followed by the Temp ID rows.

How would I convert this formula in Google sheets?

How would I combine the contents of both D and C in the same cell?
The formula is:
=QUERY(courtdates,"SELECT D, C, AQ WHERE BM = date '"&TEXT(TODAY(),"yyyy-mm-dd")&"'",0)
Try this:
=QUERY(
{
INDEX(courtdates_sheets!D:D & " " & courtdates_sheets!C:C),
courtdates_sheets!AQ:AQ,
courtdates_sheets!BM:BM
},
"SELECT Col1, Col2
WHERE Col3 = date '" & TEXT(TODAY(), "yyyy-mm-dd") & "'",
)
Where courtdates_sheets is the sheet name where courtdates named range is defined.

Resources