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))), ))
I am looking to build a phrase counter using importxml on google sheets. I have the initial formula complete and functioning most of the time, but there are a few issues.
Here is the formula:
=COUNTIF(SPLIT(REGEXREPLACE(lower(concatenate(IMPORTXML("https://www.hawkinsfamilylaw.co.uk/", "/html/body", "en_US"))), A39, SUBSTITUTE(A39, " ", "")), " "), SUBSTITUTE(A39, " ", ""))
With A39 being the phrase "divorce services".
As you can see from this page (https://hawkinsfamilylaw.co.uk/), 'divorce services' is mentioned once, but the formula is not registering this phrase.
Other phrases work, but for some reason the formula isn't finding this phrase.
Is this an issue with the importxml function, or is there a reason that this particular phrase isn't being found which is related to the structure of the formula?
Many thanks,
Sean
I'm trying to create a filtered sheet (tab) inside Google Sheets by the end of the year. I already have it set up to filter by Department, but I can't get it to filter by year.
I have a DataSheet tab where people can go in and put their raw data for Departments, Project Title, and Year. In the Validation tab, I used =UNIQUE(DataSheet!A4:A) to get the drop-down menu items list for the Reporting Tab.
Reporting Tab View
=IF(B2="All Years", "", " AND LOWER(B) = LOWER('"&B2&"') ")
=IF(A2="All Departments", "", " AND LOWER(A) = LOWER('"&A2&"') ")
`=QUERY(DataSheet!A3:C, "SELECT * WHERE 1=1"& IF(A2="All Departments", "", " AND LOWER(A) = LOWER('"&A2&"') ") & IF(B2="All Years", "", " AND LOWER(B) = LOWER('"&B2&"') "), 1)`
Above is the code that queries the DataSheet table and filters based on what I chosen for the Departments Involved and Years, but whenever I try to filter by Years it doesn't work. I was getting an error of:
Unable to parse query string for Function QUERY parameter 2:"
I tried using TO_TEXT() on the Years data in the DataSheet and in the equation from above but that did not work either. Any advice?
Below is a link to the google sheet I am working on:
https://docs.google.com/spreadsheets/d/1FoesYRCM53R_IKSqym_U3l9q_27Xo7_rJHrb35RMOaQ/edit#gid=1009160987
the formula should be:
=QUERY(DataSheet!A3:C, "where 1=1 "&
IF(A2="All Departments",, " and lower(A) = '"&LOWER(A2)&"'")&
IF(B2="All Years",, " and C = "&B2), 1)
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.
I am trying to consolidate some data and running into a bizarre issue. I am using a query function that is working perfectly in some instances but not in other. When referencing a particular sheet, it keeps outputting the values in the row beneath, which is causing aa #REF error.
Here is a copy of the Google Sheet.
Here is the formula I'm using (which again, works perfectly sometimes, but not when pulling data from certain sheets)
=QUERY(INDIRECT($B125&"!$A$2:$1000"), "SELECT E WHERE A = date '"& text($C125, "yyyy-mm-dd") &"' and B contains '"&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($E125, " " , ""),"AM", ""), "PM", "")&"' ")
You need to specify the number of headers otherwise it will try to guess which eventually results in rows being magically merged into the header causing all sorts of unpredictable behavior:
=QUERY(INDIRECT($B125&"!$A$2:$1000"), "SELECT E WHERE A = date '"& text($C125, "yyyy-mm-dd") &"' and B contains '"&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($E125, " " , ""),"AM", ""), "PM", "")&"' ",1)
All I did was add a ,1 just before the closing parenthesis so that it specifies always 1 row of headers. The format of your data is really messed up and you need to think about cleaning up your data.