TEXTJOIN string only for values matching Todays date - google-sheets

Sample Table
Date Created (A)
Tracking ID (B)
5/12/2022
'813vz633-7872'
5/12/2022
'914bz756-7423'
5/12/2022
'875vu340-5687'
5/11/2022
'475dv235-6542'
5/11/2022
'905tg183-9634'
I want to create a string that looks like this:
filter message.trackingId not in ['813vz633-7872', '914bz756-7423', '875vu340-5687']
This is achieved by using formula:
="filter message.trackingId not in ["&TEXTJOIN(", ", TRUE, B2:B4)&"]"
But I want it to automatically pull from Column B only if Column A is todays date
I tried:
="filter message.trackingId not in ["&TEXTJOIN(", ", TRUE, IF(A:A=TODAY(),TEXTJOIN("", TRUE,B2:B))&"]")
But that pulls in all values in Column B, not just for todays date
I know I am close, just need a push

use:
=TEXTJOIN(", ", 1, FILTER(B:B, A:A=TODAY()))
="filter message.trackingId not in ["&TEXTJOIN(", ", 1, FILTER(B:B, A:A=TODAY()))&"]"

Try the following:
="filter message.trackingId not in ["&TEXTJOIN(", ", TRUE, FILTER(B:B, A:A=TODAY()))&"]"
Ironically, the solution includes FILTER, which your text portion contains.
(Jinx, player0!)

Related

Google sheets sumif with odd data

I have sales data that gives me dates in a bad format. Every new sale gets automatically added to the sheet. Looks like this:
Column A
Column B
Column C
Order 1
2022-12-02T02:09:37Z
$1025.19
Order 2
2022-12-02T01:25:15Z
$873.65
This will continue on for all sales. Now the date format is UTC for whatever reason and I can't adjust that, so within this formula I have to subtract 6 hours to get it to central time. I'm trying to create an auto-updating chart that shows an average day for 7 days, so I'm trying to do a sumif formula.
Here's what I have on Sheet2:
=sumif(Sheet1!C:C,index(split((index(split(Sheet1!B:B,"T"),1)+index(split(left(Sheet1!B:B,19),"T"),2))-0.25,"."),1),A1)
Where A1 is a single date. Testing this with one date and not the range shows that it does match. When I do the range, the total comes to 0, even though multiple different dates should match. What am I doing wrong?
Assume A1 has the value: 2022-12-02T02:09:37Z
Apply this formula:
=LAMBDA(RAW,TUNEHOUR,
LAMBDA(DATE,TIME,
TEXT((DATE&" "&TIME)+TUNEHOUR/24,"yyyy-mm-dd hh:mm:ss")
)(TEXT(INDEX(RAW,,1),"yyyy-mm-dd"),REGEXREPLACE(INDEX(RAW,,2),"Z",""))
)(SPLIT(A1,"T"),-6)
returns:
2022-12-01 20:09:37
And assume you have a set of data like this:
you can apply this formula:
=ArrayFormula(
LAMBDA(DATES,AMOUNTS,START,END,DFORMAT,TFORMAT,SKIPBLANK,TUNEHOUR,
LAMBDA(DATES,AMOUNTS,DTFORMAT,START,END,
LAMBDA(DATES,TIMES,
LAMBDA(VALIDDATES,AMOUNTS,
TEXT(SUM(FILTER(AMOUNTS,VALIDDATES>=START,VALIDDATES<=END)),"$#,##0.00")
)(TEXT((DATES&" "&TIMES)+TUNEHOUR/24,DTFORMAT),IF(ISNUMBER(AMOUNTS),AMOUNTS,VALUE(REGEXEXTRACT(AMOUNTS,"^\$(.+)"))))
)(TEXT(INDEX(DATES,,1),DFORMAT),REGEXREPLACE(INDEX(DATES,,2),"Z",""))
)(SPLIT(QUERY({DATES},SKIPBLANK),"T"),QUERY({AMOUNTS},SKIPBLANK),DFORMAT&" "&TFORMAT,TEXT(START,DFORMAT)&" 00:00:00",TEXT(END,DFORMAT)&" 23:59:59")
)($B$5:$B,$C$5:$C,$B$1,$B$2,"yyyy-mm-dd","hh:mm:ss","WHERE Col1 IS NOT NULL",-6)
)
Where you enter a start date and an end date at B1 & B2 to sum up the amount with.
The provided date column will be deducted by 6 hours.
What this formula does is...
format the date column into a valid date,
compare dates from step 1 with a given start and end date as filter condition,
filter the given amount column with conditions from step 2,
sum the result of filter from step 3 as an array,
format the output as price.
Use regexreplace() and query(), like this:
=arrayformula(
query(
{
weeknum(
regexreplace(B2:B, "([-\d]+)T(\d\d:\d\d).+", "$1 $2")
-
"6:00"
),
C2:C
},
"select Col1, avg(Col2)
where Col1 is not null
group by Col1
label Col1 'week #' ",
0
)
)
I think you're trying to split the values and sum them. I can't understand fully what's the purpose of 19 in LEFT function, and why are you again splitting it? Maybe some approach similar to yours is use LEFT function with 10 characters for the date, and MID from 12th character to get the time. Then substract .25 for the 6 hours as you did, and ROUNDDOWN with 0 digits to get the only the day
=ARRAYFORMULA(ROUNDDOWN(LEFT('Sheet1'!B:B,10)+MID('Sheet1'!B:B,12,8)-0.25,0))
And then you can insert it in your SUMIF:
=SUMIF(Sheet1!C:C,ARRAYFORMULA(ROUNDDOWN(LEFT(Sheet1!B:B,10)+MID(Sheet1!B:B,12,8)-0.25,0)),A1)

How can I make correct formula for Age diff in Google sheet?

So, I wanted to claculate age from user birthdate to current date in Google sheet in my expected format. I tried few formula's from some sources, but it is just not happening.
Can anyone please guide me?
For reference and test purpose, I'm attaching one Google sheet public link. No worries if email address will be shown in Googe sheet.
Link: https://docs.google.com/spreadsheets/d/1jRlr6A3YRJIo1Ah1TSlRsDcLEDV_2BJ8YaBRS3YVC6Q/edit#gid=0
Assume birthday date is placed in range 'A2'.
Current age:
=DATEDIF(A2,TODAY(),"Y")&" year(s) "&DATEDIF(A2,TODAY(),"YM")&" month(s) "&DATEDIF(A2,TODAY(),"MD")&" day(s)"
you could use:
=INDEX(JOIN(" ",DATEDIF(A2, NOW(),
{"Y", "YM", "MD"})&{" year(s)", " month(s)", " day(s)"}))
but to make it "smart" (not show null values and use plural only when needed) try:
=INDEX(JOIN(" ", LAMBDA(a, LAMBDA(x, IF(x=0,,IF(x>1, x&a&"s", x&a)))
(DATEDIF(A2, NOW(), {"Y", "YM", "MD"})))({" year", " month", " day"})))
and for array it would be:
=INDEX(IF(ISDATE_STRICT(A2:A), TRIM(FLATTEN(QUERY(TRANSPOSE(
IFERROR(LAMBDA(a, LAMBDA(x, IF(x=0,,IF(x>1, x&a&"s", x&a)))
(DATEDIF(A2:A, NOW(), {"Y", "YM", "MD"})))({" year", " month", " day"}))),,9^9))), ))

how to concat/merge two columns with different length?

I'm new to google sheet. I have a column(E) with the date and another with a session(F), I want to merge them into one column with each date & different session just like the first few rows in column C.
I've tried "=ArrayFormula(concat(D2:D,concat(" ",F2:F5)))" in column C but only got the first date.
use:
=INDEX(QUERY(FLATTEN(FILTER(E2:E, E2:E<>"")&" "&
TRANSPOSE(FILTER(F2:F, F2:F<>""))), "where not Col1 starts with ' '", ))
see: https://stackoverflow.com/a/68775825/5632629
In your cell C1, try this formula:
=ArrayFormula(E1:E&" "&F1:F)
Well you can simply do concatenate cells like this:
CONCATENATE(E1, " ", F1)
to get what you want I think.
What you're looking for is a cartesian product. I don't have a single formula that does the entire thing for you, but I can suggest a two-step approach.
Get the cartesian product with this formula:
=ARRAYFORMULA(SPLIT(FLATTEN(E2:E9 & "|" & TRANSPOSE(F2:F5)), "|"))
This gives a pair of each date against each time in two result columns. You can then concatenate each row of them in a final result column.

Variable Cell Value Format In Query Function

I know "Format" can be used in a Query function (i.e Query(A1:G2,"Select * Format C 'MM/DD/YYY'")) but I'm stuck on how to use it in my more complicated query. Essentially I want all the selected Columns to be formatted to dates "MM/DD/YYYY", but I can't do it in the cell itself because this query is part of a variable query function that pulls data based on a user input, and only THESE column pulls are in date formats, all the other pulls are plain numbers or text. I tried putting the Format in myself but it never works or the output gives me the IfError False readout of "No Matches Found". Can anyone assist?
IFERROR(QUERY({Training!A3:AP},"select Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13,Col14,Col15,Col16,Col17,Col18,Col19,Col20,Col21,Col22,Col23,Col24,Col25,Col26,Col27,Col28,Col29,Col30,Col31,Col32,Col33,Col34,Col35,Col36,Col37,Col38,Col39,Col40,Col41,Col42 where "&TEXTJOIN(" and ", 1, IF(Lower(B3)<>"", "Lower(Col1) contains '"&Lower(B3)&"'", ),IF(Lower(B4)<>"", "Lower(Col2) contains '"&Lower(B4)&"'", ),If(Lower(B5)<>"", "Lower(Col6) contains '"&Lower(B5)&"'", ),IF(Lower(B7)<>"", "Lower(Col9) contains '"&Lower(B7)&"'", ),If(B6<>"",Vlookup(B6,Classes!G2:H,2,False)&" contains '"&B6&"'",),), 0), "No Matches Found")))
format in QUERY is buggy. use this:
=ARRAYFORMULA(IF(B2="", "Please Select Criteria",
IF(B2="Licenses", IFERROR(QUERY({Licensing!A3:D,
IF(Licensing!E3:E="",,TEXT(Licensing!E3:E, "dd/mm/yyyy")), Licensing!F3:F,
IF(Licensing!G3:G="",,TEXT(Licensing!G3:G, "dd/mm/yyyy")), Licensing!H3:H,
IF((Licensing!I3:AQ<>"")*(MOD(COLUMN(I3:AQ)+1, 4)=0),
TEXT(Licensing!I3:AQ, "dd/mm/yyyy"), Licensing!I3:AQ)},
"select "&JOIN(",", "Col"&ROW(3:7), "Col"&FILTER(ROW(9:43), NOT(MOD(ROW(9:43), 4)=0)))&"
where "&TEXTJOIN(" and ", 1, "1=1",
IF(LOWER(B3)="",,"lower(Col1) contains '"&LOWER(B3)&"'"),
IF(LOWER(B4)="",,"lower(Col2) contains '"&LOWER(B4)&"'"),
IF(LOWER(B5)="",,"lower(Col6) contains '"&LOWER(B5)&"'"),
IF(LOWER(B7)="",,"lower(Col10) contains '"&LOWER(B7)&"'"),
IF(B6="",,"Col"&MATCH(B6, Licensing!2:2, 0)&" is not null")), 0), "No Matches Found"),
IFERROR(QUERY({Training!A3:D,
IF(Training!E3:E="",, TEXT(Training!E3:E, "dd/mm/yyyy")), Training!F3:F,
IF(Training!G3:AP="",,TEXT(Training!G3:AP, "dd/mm/yyyy"))},
"select "&JOIN(",", "Col"&ROW(3:42))&"
where "&TEXTJOIN(" and ", 1, "1=1",
IF(LOWER(B3)="",,"lower(Col1) contains '"&LOWER(B3)&"'"),
IF(LOWER(B4)="",,"lower(Col2) contains '"&LOWER(B4)&"'"),
IF(LOWER(B5)="",,"lower(Col6) contains '"&LOWER(B5)&"'"),
IF(B6="",,"Col"&MATCH(B6, Training!2:2, 0)&" is not null")), 0), "No Matches Found"))))
This may not help, but I believe the issue is that the FORMAT clause in the QUERY function does not override the cell format in the output area. I did some testing, and found that with the following simplified version of your formula, I could get the format of the output to change, for example from 'mm/dd/yyyy' to 'yyyy-mm-dd'.
"select Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11
where "&TEXTJOIN(" and ", 1,
IF(Lower(B3)<>"", "Lower(Col1) contains '"&Lower(B3)&"'", ),
IF(Lower(B4)<>"", "Lower(Col2) contains '"&Lower(B4)&"'", ),
If(Lower(B5)<>"", "Lower(Col6) contains '"&Lower(B5)&"'", ),
IF(Lower(B7)<>"", "Lower(Col9) contains '"&Lower(B7)&"'", ),
If(B6<>"",Vlookup(B6,Classes!G2:H,2,False)&" contains '"&B6&"'",),
) & " Format Col9 'dd-yyyy-mm', Col11 'dd-yyyy-mm' ", 0)
But this only worked if the cell/column was formatted as Automatic. And worse, I can't reliably reproduce the behaviour yet. On another copy of the sheet, it won't change the format.
Anyway, if you want to see it working, here is a link to the cell in my copy of your sheet.
Maybe someone else will have a clearer explanation of the issue and how to address it.

Google Sheets: Joining multiple cell values from source

I'm trying to get a formula that pulls a value from a sheet based on a date to find all occurrences and join them together.
My original question is here for context.
This works really well, but if a user submits a new order at a later date for a date that already has a submission, I get the first and not any additional.
Here's my current code, which also checks for comma and space, and adds a carriage return.
=regexreplace(IFERROR(VLOOKUP(B1, IMPORTRANGE("source", "B2:C"), 2, 0)), ", ", char(10))
How can I combine multiple cell values based on criteria?
=ARRAYFORMULA(TEXTJOIN(CHAR(10),1,
REGEXREPLACE(IFERROR(QUERY(IMPORTRANGE(
"1JCOLm7ZQgR0qgtzq_98E4vDie7-FM-WlwiSZwgpB22k", "B2:C"),
"select Col2 where Col1=date'"&TEXT(B1,"yyyy-mm-dd")&"'")),
", ", CHAR(10))))

Resources