Custom order (not alpha or numeric) of query results - if-statement

Is it possible to create a custom ORDER BY function in a google sheets QUERY?
In this scenario, I don't want the results to be alphabetical nor numeric, but rather a custom order based on a predefined category list that is actually in a separate tab from both the QUERY range as well as the formula itself.
I'm not really sure where to begin: Is this even possible? Should the category list be moved to one of the other sheets? Does the category list need to be written into the formula?
Just looking for guidance at this point.
My Sheet

=ARRAYFORMULA(ARRAY_CONSTRAIN(QUERY({QUERY({Estimate!A2:H},
"where Col1 is not null"), IFERROR(VLOOKUP(QUERY({Estimate!A2:A},
"where Col1 is not null", 0),
IF(LEN(A5:A), {A5:A, ROW(A5:A)}, ), 2, 0))},
"where Col1 is not null
order by Col9", 0), 999^99, 8))

Related

Create list with value from different dynamic sheets

I have a list of values in three different sheets that are dynamic in column A, I have to put merge the three of them into a main sheet big list.
In the image the color squares are the different sheets and in the right is the merge sheet where I need this merged list with the values from all the other sheets something like this:
use:
=FILTER({'Sheet 5'!A:A; 'Sheet 6'!A:A; 'Sheet 7'!A:A};
{'Sheet 5'!A:A; 'Sheet 6'!A:A; 'Sheet 7'!A:A}<>"")
There are different ways to do that.
=QUERY(C:C,"select * where C is not null")
You can use FILTER() function like
=FILTER(C:C,C:C<>"")
Try this
=query({Sheet1!A1:A;Sheet2!A2:A;Sheet3!A1:A},"where Col1 is not null")
or
=query({Sheet1!A1:A;Sheet2!A2:A;Sheet3!A1:A};"where Col1 is not null")
according to your locale

Insert range using IF formula in SUMIF function with multiple criteria (using arrayformula)

I am using arrayformula with my sumif function which has several criterion and ranges to expand automatically across a set column (B). The formula below works perfectly:
=ARRAYFORMULA(SUMIF('DATA'!$N:$N&'DATA'!$U:$U&'DATA'!$V:$V&'DATA'!$BV:$BV,$B$6:$B&$E$30&$D$26&$C$36,'DATA'!$AG:$AG).
I want to make it more dynamic and insert an IF statement to actually refer to a range vs another based on certain conditions. For ex,
IF($A$6:$A=XX,'DATA'!$N:$N,'DATA'!$M:$M).
The formula then breaks if I do this
=ARRAYFORMULA(SUMIF(IF($A$6:$A=XX,'DATA'!$N:$N,'DATA'!$M:$M)&'DATA'!$U:$U&'DATA'!$V:$V&'DATA'!$BV:$BV,$B$6:$B&$E$30&$D$26&$C$36,'DATA'!$AG:$AG).
Any way/workaround to make it work? I tried multiple times, read multiple forums but can't find an answer.
if XX is not named range it should be in quotes
try:
=ARRAYFORMULA(SUM(IF(
IF(A6="XX", 'DATA'!N:N, 'DATA'!M:M)&DATA!U:U&DATA!V:V&DATA!BV:BV=B6:B&E30&D26&C36,
DATA!AG:AG, )))
UPDATE:
=ARRAYFORMULA(IFNA(VLOOKUP(B7:B&C7:C,
QUERY({DATA!A2:A&DATA!A1, DATA!C2:F; DATA!B2:B&DATA!B1, DATA!C2:F},
"select Col1,sum(Col5)
where Col2 = '"&D4&"'
and Col4 = '"&D3&"'
group by Col1
label sum(Col5)''"), 2, 0)))

Filter data (Not In) based on condition within two data sets in Google sheet

Have employee data set with status active and relieved. And the second data set has the time they have reported to the office. Trying to achieve the names of employee who are absent for the day using one formula. I have attached the images for easy understanding. Please find the sheet wherein I have created sample data and formula which I have used. Trying to achieve it using one array formula or query
https://docs.google.com/spreadsheets/d/1Dj7agceCBS_aCm2GVm4EQHqS8_wQYifoKLMcA0fv4fM/edit?usp=sharing
Have achieved it using Filter and Match
{"Absent For the Day";FILTER((query(importrange("1Dj7agceCBS_aCm2GVm4EQHqS8_wQYifoKLMcA0fv4fM","empdata!A2:B30"),"select Col1 where Col2='Active'")),ISERROR(MATCH((query(importrange("1Dj7agceCBS_aCm2GVm4EQHqS8_wQYifoKLMcA0fv4fM","empdata!A2:B30"),"select Col1 where Col2='Active'")),A2:A20,0)))}
try:
=ARRAYFORMULA({"Absent For the Day", "";
SPLIT(FILTER(empdata!A2:A, empdata!B2:B="active",
NOT(REGEXMATCH(empdata!A2:A, TEXTJOIN("|", 1, A2:A))))&"♦Absent", "♦")})
try:
=ARRAYFORMULA({"Absent For the Day", "";
SPLIT(QUERY(IMPORTRANGE("1Dj7agceCBS_aCm2GVm4EQHqS8_wQYifoKLMcA0fv4fM", "empdata!A2:B"),
"select Col1
where lower(Col2) = 'active'
and not Col1 matches '"&TEXTJOIN("|", 1, A2:A)&"'", 0)&"♦Absent", "♦")})

How to make column on one sheet only contain values, or combinations of said values, present in another column?

I have a Google Sheets column where the only possible values should be combinations of values from another column. So in this image, the cell with product 4 would be rejected since it is not from column C
Normally, I would just use the data validation feature, but combinations of values such as "product 1, product 2" would also not be allowed since they are not "product 1" or "product 2" exactly and data validation only allows exact values from other columns.
I tried using a custom formula with Regexmatch, but I haven't managed to work it out as to only allow values from the specified column and had to resort to hardcoding it in, as such
=regexmatch(A1,"product 1"|"product 2"|"product 3")
but when I add a new value to the data column, I have to modify the formula again so it is not an optimal solution.
How Do I go about doing this now because I haven't found much info online?
you can play this out like:
=ARRAYFORMULA(REGEXREPLACE(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(IFERROR(SPLIT(A2:A, ","))<>"",
IF(REGEXMATCH(IFERROR(SPLIT(A2:A, ",")), TEXTJOIN("|", 1, C2:C)),
REGEXEXTRACT(IFERROR(SPLIT(A2:A, ",")), TEXTJOIN("|", 1, C2:C))&",", "♦"), ))
,,999^99)), "where not Col1 contains '♦'", 0), ",$|, $", ))

How to check if a criterion is present in a range of cells in Google Sheets?

I am trying to collect time information on a maintenance worksheet for work that was completed outside of the current work week.
Right now I am referencing each date cell individually and it works but it's a massive and clunky formula. I've tried out a number of things I haven't used before but none of them seem right. COUNTIF will not work because I need to sum the range based on the value in question not being present in the current range of dates.
=SUM(SUMIFS(WT!$O$4:$O$100,WT!$C$4:$C$100,CONCATENATE("<>",$B$9),WT!$C$4:$C$100,CONCATENATE("<>",$B$10),WT!$C$4:$C$100,CONCATENATE("<>",$B$11)...
As I said, the output is correct but I want it to be more easily transferable and scale-able in the case of adding another worker.
you can do it like this in C18:
=ARRAYFORMULA(SUM(IFERROR(QUERY({WT!$C4:$F100, INDIRECT("WT!"&
ADDRESS(4, MATCH(C7, WT!$A3:3, 0), 4)&":"&
ADDRESS(100, MATCH(C7, WT!$A3:3, 0), 4))},
"select Col4
where Col5 is not null
and not Col1 matches '"&TEXTJOIN("|", 1, TEXT($B9:$B17, "yyyy-M-d"))&"'", 0))))