Count current and longest streak from null or 1 values - google-sheets

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"; ))

Related

How to get price without a sign €/l?

I use this formula to get the data:
importXML("https://at.fuelo.net/fuel/type/gasoline?lang=en"; "//table[#class=('table')]//tr")
How to get price without a sign €/l?
Use substitute() or regexreplace() with iferror(), like this:
=arrayformula(
iferror(
iferror(
0.001 *
value(
substitute(
importxml("https://at.fuelo.net/fuel/type/gasoline?lang=en", "//table[#class=('table')]//tr"),
" €/l", ""
)
),
0.001 *
importxml("https://at.fuelo.net/fuel/type/gasoline?lang=en", "//table[#class=('table')]//tr")
),
importxml("https://at.fuelo.net/fuel/type/gasoline?lang=en", "//table[#class=('table')]//tr")
)
)
Or, depending on your locale, it may be:
=arrayformula(
iferror(
iferror(
0,001 *
value(
substitute(
importxml("https://at.fuelo.net/fuel/type/gasoline?lang=en"; "//table[#class=('table')]//tr");
" €/l"; ""
)
);
0,001 *
importxml("https://at.fuelo.net/fuel/type/gasoline?lang=en"; "//table[#class=('table')]//tr")
);
importxml("https://at.fuelo.net/fuel/type/gasoline?lang=en"; "//table[#class=('table')]//tr")
)
)
The 0.001 * bit and the outer iferror() are only required when your spreadsheet locale uses period as decimal mark.
use:
=QUERY({IMPORTXML("https://at.fuelo.net/fuel/type/gasoline?lang=en";
"//table[#class=('table')]//tr")\ INDEX(SUBSTITUTE(IMPORTXML(
"https://at.fuelo.net/fuel/type/gasoline?lang=en";
"//table[#class=('table')]//tr"); " €/l"; "");;2)};
"select Col1,Col4,Col3")
update:
=ARRAYFORMULA(IFNA(TEXT(REGEXEXTRACT(SUBSTITUTE(
IMPORTXML("https://at.fuelo.net/fuel/type/gasoline?lang=en";
"//table[#class=('table')]//tr"); "."; ",");
"\d+,\d+")*GOOGLEFINANCE("currency:EURUSD"); "0.00"); TRIM(
IMPORTXML("https://at.fuelo.net/fuel/type/gasoline?lang=en";
"//table[#class=('table')]//tr"))))

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

Arrayformula of sequeses

I have a list of reservations with a startDate, endDate and itemNumber. Now i want to have a list of all the dates between those dates and the itemnumber next to it. I have this working for 1 reservation, but i can't get it to work with multiple reservations in one arrayformula.
I have a sample sheet (edit rights) with my formula's and the expected outcome.
Someone here that can help me out?
Sample sheet
Two Formula Version:
Item Column (Assuming K):
=ArrayFormula(TRANSPOSE(SPLIT(JOIN(,REPT(Reservation!D2:D&",",1+Reservation!C2:C-Reservation!B2:B)),",")))
or
=ArrayFormula(
IFNA(
HLOOKUP(
"StartDate",
Reservation!B:B,
MATCH(
FILTER(K3:K,K3:K>0),
Reservation!D2:D,
0
)+1,
0
)+IFNA(
ROW(K3:K)-2-MATCH(K3:K,K3:K,0)
)
)
)
This generates the list of Items based on the difference between the dates.
Date Column (Assuming J):
=ArrayFormula(IFNA(HLOOKUP("StartDate",Reservation!B:B,MATCH(FILTER(K3:K,K3:K>0),Reservation!D2:D,0)+1,0)+IFNA(ROW(K3:K)-2-MATCH(K3:K,K3:K,0))))
or
=ArrayFormula(
TRANSPOSE(
SPLIT(
JOIN(,
REPT(
Reservation!D2:D&",",
1+Reservation!C2:C-Reservation!B2:B
)
),
","
)
)
)
Based on the Item, get its offset in the Item column (above) and add it to the Start Date for the corresponding item.
Single Formula Version:
Looks very messy, but is mostly just substituting K's into second formula above.
=ArrayFormula(
{
IFNA(HLOOKUP("StartDate",Reservation!B:B,MATCH(TRANSPOSE(SPLIT(JOIN(,REPT(Reservation!D2:D&",",1+Reservation!C2:C-Reservation!B2:B)),",")),Reservation!D2:D,0)+1,0)+IFNA(SEQUENCE(COUNTA(TRANSPOSE(SPLIT(JOIN(,REPT(Reservation!D2:D&",",1+Reservation!C2:C-Reservation!B2:B)),","))))-MATCH(TRANSPOSE(SPLIT(JOIN(,REPT(Reservation!D2:D&",",1+Reservation!C2:C-Reservation!B2:B)),",")),TRANSPOSE(SPLIT(JOIN(,REPT(Reservation!D2:D&",",1+Reservation!C2:C-Reservation!B2:B)),",")),0))),
TRANSPOSE(SPLIT(JOIN(,REPT(Reservation!D2:D&",",1+Reservation!C2:C-Reservation!B2:B)),","))
})
Or if you prefer:
=ArrayFormula(
{
IFNA(
HLOOKUP(
"StartDate",
Reservation!B:B,
MATCH(
TRANSPOSE(
SPLIT(
JOIN(,
REPT(
Reservation!D2:D&",",
1+Reservation!C2:C-Reservation!B2:B
)
),
","
)
),
Reservation!D2:D,0
)+1,
0
)+IFNA(
SEQUENCE(
COUNTA(
TRANSPOSE(
SPLIT(
JOIN(,
REPT(
Reservation!D2:D&",",
1+Reservation!C2:C-Reservation!B2:B
)
),
","
)
)
)
)-MATCH(
TRANSPOSE(
SPLIT(
JOIN(,
REPT(
Reservation!D2:D&",",
1+Reservation!C2:C-Reservation!B2:B
)
),
","
)
),
TRANSPOSE(
SPLIT(
JOIN(,
REPT(
Reservation!D2:D&",",
1+Reservation!C2:C-Reservation!B2:B
)
),
","
)
),
0
)
)
),
TRANSPOSE(
SPLIT(
JOIN(,
REPT(
Reservation!D2:D&",",
1+Reservation!C2:C-Reservation!B2:B
)
),
","
)
)
})

Google sheets array formula to lookup date from another table after removing spaces in lookup column

(Due to my organization policies I cannot share a sample sheet.)
I have two sheets with data like so:
Sheet1
Sheet2
Now, in Sheet1, in column C, I am looking for an ARRAYFORMULA that will look up the value in Sheet1!A:A by matching the substring in Sheet2!A:A after removing the spaces from Sheet2!A:A and then returning the value from the row in Sheet2!B:B.
I came up with a non-ARRAYFORMULA formula to get the data per-row (in Sheet1!C:C below). But my real data-sets have thousands of rows and I don't want to have to copy/paste a formula into each one.
Each row has a formula that looks like so:
=TEXTJOIN(
", "
, TRUE
, IFNA(
FILTER(
Sheet2!B:B
, Sheet2!B:B <> ""
, Sheet2!A:A <> ""
, NOT(
ISERROR(
SEARCH(
REGEXREPLACE(Sheet2!A:A, " ", "")
, A2
)
)
)
)
, "not found"
)
)
I tried to convert this to an ARRAYFORMULA in Sheet1!B2 but it doesn't yield the expected result. The formula is:
=ArrayFormula(
TEXTJOIN(
", "
, TRUE
, IFNA(
FILTER(
Sheet2!B:B
, Sheet2!B:B <> ""
, Sheet2!A:A <> ""
, NOT(
ISERROR(
SEARCH(
REGEXREPLACE(Sheet2!A:A, " ", "")
, A2:A
)
)
)
)
, "not found"
)
)
)
Ok, I finally got it to work with the substring and SEARCH.
=Array_Constrain(TRANSPOSE(ArrayFormula(REGEXREPLACE(REGEXREPLACE(SPLIT(TEXTJOIN(", ",1,{ArrayFormula(IFERROR(HLOOKUP("Value",Sheet2!B:B,ArrayFormula(Transpose(SEQUENCE(COUNTA(Sheet2!A2:A),1,2))*(SEARCH(TRANSPOSE(SUBSTITUTE(FILTER(Sheet2!A2:A,LEN(Sheet2!A2:A))," ",)),FILTER(A2:A,LEN(A2:A)))>0)),0))),ArrayFormula(IF(SEQUENCE(COUNTA(A2:A)),";",""))}),", ;",0,0),"^, ",),"^$","not found"))),COUNTA(A2:A),1)
"Readable" version:
=Array_Constrain(
TRANSPOSE(
ArrayFormula(REGEXREPLACE(
REGEXREPLACE(
SPLIT(
TEXTJOIN(
", ",
1,
{
ArrayFormula(IFERROR(
HLOOKUP(
"Value",
Sheet2!B:B,
ArrayFormula(
Transpose(
SEQUENCE(COUNTA(Sheet2!A2:A),1,2)
)*
(SEARCH(
TRANSPOSE(
SUBSTITUTE(
FILTER(
Sheet2!A2:A,
LEN(Sheet2!A2:A)
),
" ",
)
),
FILTER(A2:A,LEN(A2:A))
)>0)
),
0
)
)),
ArrayFormula(IF(
SEQUENCE(COUNTA(A2:A)),
";",
""
))
}
),
", ;",
0,
0
),
"^, ",
),
"^$",
"not found"
))
),
COUNTA(A2:A),
1
)

Shuffle comma-separated list of values in one cell (Google Sheets)

I'm wondering if anyone could give me a helping hand in shuffling a comma-separated list of values in one cell in Google sheets. My data looks like this:
peter, andrew, mike, michael, ..., thomas
I'd like to randomly shuffle this string for each row and I have about a thousand rows that all have one cell that looks like this.
Any formula or link to a page where I can get closer to a solution would be greatly appreciated.
Draggable Single Formula
Here's a formula if you're ok with dragging a formula down:
=ArrayFormula(
JOIN(
", ",
Array_Constrain(
SORT(
TRANSPOSE(
{
SPLIT(A1, ", ");
RANDARRAY(1,COUNTA(SPLIT(A1, ", ")))
}),
2,
),
COUNTA(SPLIT(A1,", "))
,1
)
)
)
Two ArrayFormulas
It may be possible to combine these two into one, so I may revisit this later.
Make sure you have three columns clear. I chose C as my start column.
=ArrayFormula(
SORT(
{
ARRAY_CONSTRAIN(
SPLIT(
TRANSPOSE(
SPLIT(
TEXTJOIN(
",",
1,
(SEQUENCE(COUNTA(A:A))-1)&"|"&SPLIT(FILTER(A:A&", ",LEN(A:A)),", ")
),
","
)
),
"|"
),
COUNTA(
SPLIT(TEXTJOIN(", ",1,A:A),", ")
),
2
),
RANDARRAY(
COUNTA(
SPLIT(
TEXTJOIN(", ",1,A:A),
", "
)
),
1
)
},1,1,3,1)
)
Final result.
=ArrayFormula(
TRANSPOSE(
SPLIT(
REGEXREPLACE(
TEXTJOIN(
", ",
,
UNIQUE(
TRANSPOSE(
IF(
TRANSPOSE(FILTER(C:C,LEN(C:C)))=FILTER(C:C,LEN(C:C)),
FILTER(D:D,LEN(D:D)),
";"
)
)
)
),
", (;, )+",
";"
),
";"
)
)
)
The tricky part was getting the "group concatenation" to work.

Resources