Simplify google sheet formula "SUM / INDEX / MATCH" - regex

I am trying to use google sheet to create a roster formula, to sum up the duty hour per week using INDEX/MATCH/SUM.
But it's too long, is there any way to simplify the formula?
Also, I realize "MATCH" cannot recognize blank cell (N20), can that be fixed too?
=IFERROR(SUM(INDEX($O$12:$O$20,MATCH(D17,$N$12:$N$20,0)),INDEX($O$12:$O$20,MATCH(E17,$N$12:$N$20,0)),INDEX($O$12:$O$20,AND(F17,$N$12:$N$20,0)),INDEX($O$12:$O$20,MATCH(G17,$N$12:$N$20,0)),INDEX($O$12:$O$20,MATCH(H17,$N$12:$N$20,0)),INDEX($O$12:$O$20,MATCH(I17,$N$12:$N$20,0)),INDEX($O$12:$O$20,MATCH(J17,$N$12:$N$20,0))),"Err")

try:
=ARRAYFORMULA(MMULT(IFERROR(REGEXREPLACE(UPPER(B6:H14), "^"&TEXTJOIN("$|^", 1, L1:L10)&"$",
VLOOKUP(REGEXEXTRACT(UPPER(B6:H14), "^"&TEXTJOIN("$|^", 1, L1:L10)&"$"), L1:M10, 2*
SIGN(ROW(A6:A14)), 0)&""), UPPER(B6:H14))*1, TRANSPOSE(COLUMN(B:H))^0))

Franco, since your post says your end goal is to "sum up the duty hour per week," I take that to mean all you need in the end is a single number.
Try this (which will give you total hours for your block that runs B6:H22:
=ArrayFormula(SUM(COUNTIF(B6:H22,$L$1:$L$8)*$M$1:$M$8))
If you need to see the breakdown per code, you can use this:
=ArrayFormula({$L$1:$L$8,COUNTIF(B6:H22,$L$1:$L$8)*$M$1:$M$8})
Just replace "B6:H22" with the reference of each calendar block to get the sum or the breakdown for other weeks.

Related

Google sheets IF stops working correctly when wrapped in ARRAYFORMULA

I want this formula to calculate a date based on input from two other dates. I first wrote it for a single cell and it gives the expected results but when I try to use ARRAYFORMULA it returns the wrong results.
I first use two if statements specifycing what should happen if either one of the inputs is missing. Then the final if statement calculates the date if both are present based on two conditions. This seems to work perfectly if I write the formula for one cell and drag it down.
=IF( (LEN(G19)=0);(U19+456);(IF((LEN(U19)=0) ;(G19);(IF((AND((G19<(U19+456));(G19>(U19+273)) ));(G19);(U19+456))))))
However, when I want to use arrayformula to apply it to the entire column, it always returns the value_if_false if neither cell is empty, regardless of whether the conditions in the if statement are actually met or not. I am specifically talking about the last part of the formula that calculates the date if both input values are present, it always returns the result of U19:U+456 even when the result should be G19:G. Here is how I tried to write the ARRAYFORMULA:
={"Date deadline";ARRAYFORMULA(IF((LEN(G19:G400)=0);(U19:U400+456);(IF((LEN(U19:U400)=0);
(G19:G400);(IF((AND((G19:G400<(U19:U400+456));(G19:G400>(U19:U400+273)) ));(G19:G400);(U19:U400+456)))))))}
I am a complete beginner who only learned to write formulas two weeks ago, so any help or tips would be greatly appreciated!
AND and OR are not compatible with ARRAYFORMULA
Replace them by * or +
Try
={"Date deadline";ARRAYFORMULA(
IF((LEN(G19:G400)=0),(U19:U400+456),
(IF((LEN(U19:U400)=0), (G19:G400),
(IF((((G19:G400<(U19:U400+456))*(G19:G400>(U19:U400+273)) )),(G19:G400),
(U19:U400+456)))
))
)
)}
Keep in mind you cannot use AND, OR operators in an arrayformula, so you must find an alternative method such as multiplying the values together and checking them for 0 or 1 (true*true=1)
I am gathering based on your formula's and work that you want to have the following:
If G19 is blank show U19 + 456
If U19 is blank show G19
If G19 is less than U19 + 456 but greater than U19 + 273 show G19
Otherwise show U19 + 456
I'm not too sure what you want to happen when both columns G and U are empty. Based on your current formula you are returning an empty cell + 456... but with this formula it returns an empty cell rather than Column U + 456
Formula
={"Date deadline";ARRAYFORMULA(TO_DATE(ARRAYFORMULA(IFS((($G19:$G400="")*($U19:$U400=""))>0,"",$G19:$G400="",$U19:$U400+456,$U19:$U400="",$G19:$G400,(($G19:$G400<$U19:$U400+456)*($G19:$G400>$U19:$U400+273))>0,$G19:$G400,TRUE,$U19:$U400+456))))}

Importhtml Query Extract Between String

I'm trying to find a formula that fits two tables
=QUERY(IMPORTHTML(A1,"table", 16), "Select Col4")
output is
Page 1/10Page 2/10Page 3/10Page 4/10Page 5/10Page 6/10Page 7/10Page 8/10Page
9/10Page 10/10
Another:
=QUERY(IMPORTHTML(A2,"table", 16), "Select Col4")
output is
Page 1/3Page 2/3Page 3/3
I want to extract the digits between "space" and "/" Is there a way to do this in this formula itself?
I then tried this
=transpose(SPLIT(REGEXREPLACE(A2,"Page|/10","~"),"~",0,1))
This also doesn't work since I have to manually change /10 to /3 in the second formula
Is there any way to achieve this for both data?
The sheet is here
try:
=ARRAYFORMULA(IF(ROW(A1:B)<=(1*{
REGEXEXTRACT(IMPORTXML(A1, "//option[#value='21']"), "\d+$"),
REGEXEXTRACT(IMPORTXML(B1, "//option[#value='21']"), "\d+$")}),
ROW(A1:B), ))

How to extract a dynamic bunch of words between two patterns using regex

I've been trying to extract a (dynamic) bunch of words from an invoice. As this is the product description, it changes for each invoice. I tried to use the productnumber and a lookbehind, but that wouldn't always work, because there are other 6-8digitnumbers in the same invoice, is there a way to set the 6-8digitnumber and the date ahead also as a reference?
Description Productnumber Delivery Amount VAT Price excl. Price incl. Value excl. Value incl.
BenQ XL2430T (24", 1920 x 1080 Pixels) 2774800 21.11.2014 1 8.00% 323.15 349.00 323.15 349.00
LG Nexus 5X (32GB, Quarz, 5.20", Single SIM, 12.30Mpx, 4G) 5636609 03.03.2016 1 8.00% 276.85 299.00 276.85 299.00
So what I'd want to extract in this case is
BenQ XL2430T (24", 1920 x 1080 Pixels)
LG Nexus 5X (32GB, Quarz, 5.20", Single SIM, 12.30Mpx, 4G)
Is this even possible or am I trying the impossible?
As for code so far I extract the product number with:
\b\d{6,7}(?=\s+(?:0[1-9]|[12]\d|3[01])\.(?:0[1-9]|1[0-2])\.[12]\d{3})
but I just can't get around to include that in a lookahaed of the productnumber...
(that also only gives me the first result and I'd need the second product code extracted as well)
Hopefully this is understandable and it'd be much appreciated of somebody could help.
cheers
^(?!Description Productnumber)[\w\s(?,".]+\)?\s(?=[\d]{6,8})
Demo and explanation on syntax of the regex used:
https://regex101.com/r/HBvG3K/5

Replace Content of a cell based on a list of options in Google Sheets

For years I have been using a very long formula to help me achieve what I am going to ask here.
Basically, every month I download my Credit Card statement and use a bunch of formulas to sum it up in a better way to import into my accounting software. What my formulas do is that it reads the Description in each row and based on the content of that row it rewrites that description.
For example: In my credit card it may say "Starbucks Main St.", so it looks for that information in a list and if it finds "Starbucks", it will rewrite (in the cell where the formula is located) to "Coffee".
So, what I have is:
Column B > Original Description from Credit Card Statement
Column F > Keyword to be found
Column G > New description
The problem is that I use an IF Search formula that has to be as long as the size of that list. It works, but I wonder if it can't be simplified. Another "issue" is that I can't use an arrayformula, so putting the formula on top of the spreadsheet and it would expand to the whole statement.
Here's an example:
https://docs.google.com/spreadsheets/d/14255Sz28ItSMZ32EebIFiAHQFxtyCJakN5q3gYUB-N0/edit#gid=0
ANY ideas?
try:
=ARRAYFORMULA(PROPER(IFNA(VLOOKUP(REGEXEXTRACT(PROPER(B2:B);
SORT(TEXTJOIN("|"; 1; PROPER(G2:G)); 1; 0)); G2:H; 2; 0); B2:B)))

SUMIF Array Formula with "GREATER THAN"

I know this may work:
=ArrayFormula(sum(SUMIF(D2:D9&F2:F9,J2:J3&H2,E2:E9)))
But I don't know how to find any solution for this
=ArrayFormula(sum(SUMIF(D2:D9&F2:F9,J2:J3&(">"&H2),E2:E9)))
Basically, I want to SUMIF with multiple criterias with array formula. But I can't find a way with criteria that greater than something
this is the sample case: https://docs.google.com/spreadsheets/d/1lyPSurAudZOAn2HHGPaKcgmwso46f3K4dVYA6dwlDjM/edit#gid=0
the case is about summing the quantity given from each activity, given some range of date.
array formula is needed since I want the list of activity to be flexibly added, without me having to edit the formula.
as far as I know, sumifs cant be used because sumifs doesn't work with array formula
try:
=ARRAYFORMULA(SUM(IF((F2:F>H2)*(REGEXMATCH(D2:D,
TEXTJOIN("|", 1, J2:J))), E2:E, )))
or try:
=SUM(FILTER(E2:E, REGEXMATCH(D2:D, TEXTJOIN("|", 1, J:J)), F2:F>H2))
Some alternative:
sumif and vlookup==>
=arrayformula(sumif((1-isna(vlookup(D2:D9,J2:J3,1)))*F2:F9,">" & H2,E2:E9))
sum if and vlookup:
=arrayformula(sum(if((1-isna(vlookup(D2:D9,J2:J3,1)))*F2:F9>H2,E2:E9,0)))
Sum and vlookup:
=arrayformula(sum((iferror(vlookup(D2:D9,J2:J3,1),"")=D2:D9)*(F2:F9>H2)*E2:E9))