Google Sheets: IFS statement wont return date - if-statement

I'm currently using the following formula:
=IFS(regexmatch(A2,"Malaysia"),
B2-dataset!B3,REGEXMATCH(A2,"Saudi Arabia"),
B2-dataset!B7,REGEXMATCH(A2,"Taiwan"),
B2-dataset!B11,REGEXMATCH(A2,"Russia"),
B2-dataset!B15,REGEXMATCH(A2,"Greece"),
B2-dataset!B19,REGEXMATCH(A2,"South Africa"),
B2-dataset!B23,REGEXMATCH(A2,"UAE"),
B2-dataset!B27,REGEXMATCH(A2,"Albania"),
B2-dataset!B31,REGEXMATCH(A2,"India"),
B2-dataset!B35,REGEXMATCH(A2,"South Korea"),
B2-dataset!B39,REGEXMATCH(A2,"Turkey"),
B2-dataset!B43)
The idea is that B2 (currently as =date(dd/mm/yyyy) has a deadline date. C2 (in which the formula houses) should show the date when everything should be delivered.
Currently the outcome is a number, not a date. I've tried IF statement, which delivers a date but I can only add 3 arguments. Can someone help me?
Kind regards

if your current output is number like 40000+ it's ok and it's just formatting issue. either you will format it internally or use a formula.
try:
=TEXT(IFS(regexmatch(A2,"Malaysia"),
B2-dataset!B3,REGEXMATCH(A2,"Saudi Arabia"),
B2-dataset!B7,REGEXMATCH(A2,"Taiwan"),
B2-dataset!B11,REGEXMATCH(A2,"Russia"),
B2-dataset!B15,REGEXMATCH(A2,"Greece"),
B2-dataset!B19,REGEXMATCH(A2,"South Africa"),
B2-dataset!B23,REGEXMATCH(A2,"UAE"),
B2-dataset!B27,REGEXMATCH(A2,"Albania"),
B2-dataset!B31,REGEXMATCH(A2,"India"),
B2-dataset!B35,REGEXMATCH(A2,"South Korea"),
B2-dataset!B39,REGEXMATCH(A2,"Turkey"),
B2-dataset!B43), "dd/mm/yyyy")

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))))}

Using regextract and importrange together make a "duplicate" formula

I have a spreadsheet where I look if the data (website) already exist on the master sheet.
=if(countif(importrange("Spreadsheet Key","Leads!N:N"),K2)>0,"COMPANY EXISTS!","")
But the above formula is not dynamic enough. If there are companies with co.uk and on the master sheet if it's registered under .com, it won't show "COMPANY EXISTS!"
So I changed to the formula to look for works after before and after "." on a website.
=ARRAYFORMULA(REGEXEXTRACT(UNIQUE(SUBSTITUTE(importrange("Spreadsheet Key","Leads!N:N"),"www.","")), "([0-9A-Za-z-]+)\."))
But it's not working if I try to incorporate with if and countif.
=if(COUNTIF(ARRAYFORMULA(REGEXEXTRACT(SUBSTITUTE(importrange("Spreadsheet Key","Leads!N:N"),"www.",""), "([0-9A-Za-z-]+)\."),L2:L)>0,"Company Exist!",""))
It shows 'Wrong number of arguments to IF. Expected between 2 and 3 arguments, but got 1 arguments'
Can anyone help me out on where I am making the mistake?
Spreadsheet link- https://docs.google.com/spreadsheets/d/1La3oOWiM5KpzRY0MLLEUQC25LzDuQlqTjgFp-VlS8Bo/edit#gid=0
Edited: Made a mistake beforehand, didn't specify on that cell its looking against
Your formula had a typo. You are not closing the Arrayformula and the Countif correctly (the array formula closing parenthesis should go before the , of the count if). So change this:
=if(COUNTIF(ARRAYFORMULA(REGEXEXTRACT(SUBSTITUTE(importrange("Spreadsheet Key","Leads!N:N"),"www.",""), "([0-9A-Za-z-]+)\."),L2:L)>0,"Company Exist!",""))
To this:
=if(COUNTIF(ARRAYFORMULA(REGEXEXTRACT(SUBSTITUTE(IMPORTRANGE("Spreadsheet Key","Leads!N:N"),"www.",""), "([0-9A-Za-z-]+)\.")),L3:L)>0,"Company Exist!","")
I hope this has helped you. Let me know if you need anything else or if you did not understood something. :)
try:
=ARRAYFORMULA(IFNA(IF(IFNA(REGEXEXTRACT(SUBSTITUTE(IMPORTRANGE(
"1bnz7Y_xVN9Jo80aCBBeMBMJBnMDHkbZQUWnmL20CRi8", "Leads!N:N"),
"www.", ), "([0-9A-Za-z-]+)\."))>0, "Company Exist!", )))

Google Sheets WENN Date and Checkbox

i'm trying to figure out, how I can get my formula working.
It's telling me I need a valid date.
So if i'm going for this :
J3=checkbox, D5=date formated with =today(), G5=number between 1-30
=WENN(J3=FALSE;D5+G5)
This works fine ( today() + 1-30 )
Now here comes the error :
=WENN(J3=FALSE;D5+G5;);WENN(J3=TRUE;D5+7;)
This does not work because now it's telling me I need the valid date.
So my question is, how I can get it work?
try like this:
=IF(D3=FALSE; A3+C3; A3+7)
for arrayformula use:
=ARRAYFORMULA(IF(A3:A="";;IF(D3:D=FALSE; A3:A+C3:C; A3:A+7))

Google Sheet formula to convert Youtube's API ISO 8601 duration format

I have a google sheet script that fetches youtube's video durations. The problem is the time data is in the ISO 8601 format.
For example:
PT3M23S
The formula I'm using right now does a good job converting this into a more readable format.
=iferror(REGEXREPLACE(getYoutubeTime(B20),"(PT)(\d+)M(\d+)S","$2:$3"))
It converts the above into a more readable format 3:23
Now the issue at hand is if the duration of the video is exactly 3 minutes or if the video is shorter than 1 minute regexreplace doesn't reformat it.
Instead it reads
PT4M OR PT53S
Is there a way to edit the formula to address each variant that potential could occur?
Where it would format PT4M into 4:00 or PT53S into 0:53
Lastly, if the seconds in the duration are between 1-9 the API returns a single digit value for the seconds. Which means the formula above will look wrong. For example, PT1M1S is formatted into 1:1 when it should read 1:01
It would be great if the formula could account for the first 9 seconds and add a 0 to make it more readable.
Thanks for reading this far, if anyone could help me out I'd very much appreciate it.
Just in case its easier to do this within the script itself here's the custom script that retrieves the video duration.
function getYoutubeTime(videoId){
var url = "https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=" + videoId;
url = url + "&key=";
var videoListResponse = UrlFetchApp.fetch(url);
var json = JSON.parse(videoListResponse.getContentText());
return json["items"][0]["contentDetails"]["duration"];
}
Is very ugly, but seems to work for the examples provided:
=iferror(left(mid(A1,3,len(A1)-2),find("M",mid(A1,3,len(A1)-2))-1)*60,0)+substitute(REGEXreplace(mid(A1,3,len(A1)-2),"(.+M)",""),"S","")
Outputs seconds, eg 203 from PT3M23S. To change to 00:03:23 wap the above formula in ( ... )/86400 and format result as Time.
Script Solution:
function iso8601HMparse(str) {
return str.replace(/PT(\d+(?=M))?M?(\d+(?=S))?S?/g,function(mm,p1,p2){//regex to get M and S value
return [0,p1,p2].map(function(e){
e = e ? e:0;
return ("00"+e).substr(-2); //fix them to 2 chars
}).join(':');
})
}
Splice it in your script like:
return iso8601HMparse(json["items"][0]["contentDetails"]["duration"].toString());
Spreadsheet Function:
=TEXT(1*REGEXREPLACE(REGEXREPLACE(A1,"PT(\d+M)?(\d+?S)?","00:00$1:00$2"),"[MS]",),"MM:SS")
Late to the party, but here's what I'm using:
=TIMEVALUE(
IFERROR(TEXT(MID(A1,3,FIND("H",A1)-3),"00"),"00")&":"&
IFERROR(TEXT(MID(A1,IFERROR(FIND("H",A1)+1,3),FIND("M",A1)-IFERROR(FIND("H",A1)+1,3)),"00"),"00")&":"&
IFERROR(TEXT(MID(A1,IFERROR(FIND("M",A1)+1,3),FIND("S",A1)-IFERROR(FIND("M",A1)+1,3)),"00"),"00"))
You can also stick ARRAYFORMULA in front of this and change A1 to a a column to get values for a whole list of them.

IF Statement with Network days

I'm trying to write a formula using an IF and Networkdays function. I basically want this formula to look in column J3 and see if there is a date. If there is a date the it should return the number of work days between the completion date and the discovery date.
If J3 (completion date) is blank, which means it hasn't benn completed, then I just want it to return blank
Try something like this:
=IF(J3 = "", "", NETWORKDAYS(A3, J3))
You already had 50% of the formula.
The IF statement will check whether or not J3 is blank (i.e. ""). If that is true, it will return a blank value. If it's false meaning that there is something in there, it will return your formula.
Let me know if that works.
Here is the formula that I use:
=IF(NETWORKDAYS($G7,$H7)>0, NETWORKDAYS($G7,$H7),"-")