IF Formula to serve multiple scenarios - arrays

I`m looking for a formula to serve the followings
A, B, C & D are dates
if C falls between A & B then "ok",
if not then "OK-Overdue",
if C blank and D>B then "under-review"
if C blank and D<B then "Pending"
D will be always Today()

It was a bit unclear I must admit, the formula's result will be in another cell, let's say E.
I am assuming that A is always smaller than B. As in, A is start date, B is end date.
=IF(AND(A1<C1;C1<B1);"OK";"OK-Overdue")
This will work, but not when C is blank. Let's check that first:
=IF(ISBLANK(C1);"BLANK";IF(AND(A1<C1;C1<B1);"OK";"OK-Overdue"))
Okay, and we didn't want to print "BLANK" when it's blank, we want to make further checks. Let's make the
if C blank and D>B then "under-review" if C blank and D<B then "Pending"
check first, then we just replace "BLANK" in the formula we have done so far. Okay, let's do the D/B-checks:
=IF(B1<D1;"under-review";"Pending")
Okay, finally let's put that in the "BLANK"-space, and here it is...
Final Result:
=IF(ISBLANK(C1);IF(B1<D1;"under-review";"Pending");IF(AND(A1<C1;C1<B1);"OK";"OK-Overdue"))
Hope it works like you want it to, just let me know if something's off. NOTE: I don't check if D=B. So if D=B, it will say "Pending". :)

Related

how to sequence a set with reseting condition only if previous state got terminated

given the specific set of columns, I'm looking for a way to turn red cells into blank cells either within the COUNTIF process or afterward.
formula I use to get (partially) correct answer is:
=ARRAYFORMULA(IF(A2:A="",,IF(NOT(REGEXMATCH(TO_TEXT(B2:B), "\-")),
COUNTIFS(A2:A&D2:D, A2:A&D2:D, ROW(A2:A), "<="&ROW(A2:A)), )))
here is a copy of my sheet: - CC -
consider yellow cells as RESET/TERMINATION for ID
after each reset, ID gets upgraded (E column)
E column is just a helper for better visualization - it's not part of the dataset
A column is unsorted and it may be even ungrouped
When I make a copy of your sheet (the only option provided), the negative numbers in Col B are actually all text. So I didn't backtrack into the best way of doing this from the original data in Col A. Instead, I just worked with Cols A:D as you currently have them (though I suspect that you don't need the helpers) and with your original "close" formula as you wrote it.
That said, this should work to deliver your desired result as shown:
=ArrayFormula({"DESIRED OUTPUT";IF(A2:A="",,IF(VLOOKUP(A2:A&"~"&COUNTIFS(A2:A,A2:A,ROW(A2:A),"<="&ROW(A2:A))-1,{SPLIT(UNIQUE(A2:A)&"~0|0","|");A2:A&"~"&COUNTIFS(A2:A,A2:A,ROW(A2:A),"<="&ROW(A2:A)),C2:C},2,FALSE)<>0,,IF(NOT(REGEXMATCH(TO_TEXT(B2:B), "\-")), COUNTIFS(A2:A&D2:D, A2:A&D2:D, ROW(A2:A), "<="&ROW(A2:A)), )))})
My contribution is this part:
IF(VLOOKUP(A2:A&"~"&COUNTIFS(A2:A,A2:A,ROW(A2:A),"<="&ROW(A2:A))-1,{SPLIT(UNIQUE(A2:A)&"~0|0","|");A2:A&"~"&COUNTIFS(A2:A,A2:A,ROW(A2:A),"<="&ROW(A2:A)),C2:C},2,FALSE)<>0,, [most of your previous formula])
In plain English, this looks up the last occurrence of each ID. Only if that last occurrence had a 0 value in Col C will the results of your main formula be shown.
I stacked SPLIT(UNIQUE(A2:A)&"~0|0","|") on top of the actual ID~Row, Col C values so that the first occurrence of any ID will still find a 0 and will not result in an error. (Adding IFERROR would have unnecessarily lengthened the formula.)
NOTE 1: I assumed here that you original "close" formula works as you expect. I did not test it under close scrutiny. I just plugged it into my extended formula that determines where to place results.
NOTE 2: Normally, I don't get into complex formulas on these forums, for the sheer sake of time and the fact that I stay very busy. But you help out a ton on this forum, so I was happy to invest back into your own rare inquiry here.

Creating A Concatenated ID w/ Leading Zeroes Using Sequence in Google Sheets

I am very close here but due to my still novice understanding of Regular Expressions, I am not getting exactly the results I want.
In B1 sits a variable used to create a sequence.
The desired output is
Team01,Team02,Team03,Team04,Team05,Team06,Team07,Team08,Team09,Team10,Team11,Team12
The data in that table is generated by this formula in B3
=ARRAYFORMULA({"TeamID";"Team"&SEQUENCE(SUBSTITUTE(B1,"\\10\\2","^[1-9]\d*(?:\.\d{1,2})?$"))})
I know that the formula isn't working because the RegEx isn't correct and maybe i need to be using other tools, but I'm still new to this and trying to piece together what needs to change.
You can also try the even shorter and "easier to the eye"
=ARRAYFORMULA("Team"&TEXT(SEQUENCE(B1), "0#"))
or even
=INDEX("Team"&TEXT(SEQUENCE(B1), "0#"))
try:
=ARRAYFORMULA(TEXT(SEQUENCE(B1), "\T\e\a\m0#"))
or shorter:
=INDEX(TEXT(SEQUENCE(B1), "\T\e\a\m0#"))

Stack multiple columns into one without ignore blank cells

For a stack of several columns and filtering the blank cells, #player0 told me to do it as follows:
https://stackoverflow.com/a/60028660/11462274
But I came across the need for the blank cells not to be ignored, because I'm going to use a script on four different spreadsheets, and each one of them will send data to the first blank row of the columns, so it may happen that some columns have more data than the others and as I am going to record values manually in the column on the side, if I change the positions it will mess up what I record manually.
:
A B C D
E F G H
J K L
N
Expected result:
A
B
C
D
E
F
G
H
J
K
L
N
These blank spaces will be necessary so that when new data is recorded in the columns, the old ones do not change position, remain in the same place where they are.
Would it be possible to do that?
Note: I have already looked in some places saying that if I do this,
the spreadsheet would be immense because of the number of blank lines
that it would take into account. I imagine that it would be necessary
only the blank cells until the last line that has data at the moment,
the rest would not be necessary.
But I was unable to adjust to make this possible.
My solution is so simple it hurts, but you can use =FLATTEN(A1:D)
Yes, that easy.
Apparently, Google never documented this FLATTEN function, but it works PERFECTLY for what you want and what I've needed as well.
Hope someone finds this even though it's been answered, I know I've needed it forever haha.
You want to achieve the following situation.
From
A B C D
E F G H
J K L
N
To
A
B
C
D
E
F
G
H
J
K
L
N
In above case, you want to use only the values from A to N. You don't want to include the empty values after the value of N.
If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
Modified formula:
=TRANSPOSE(SPLIT(REGEXREPLACE(TEXTJOIN(",",FALSE,A1:D,"#"),",+#",","),",",,FALSE))
Join the values of "A1:D" using TEXTJOIN().
Remove the empty values after the last character using REGEXREPLACE().
Split the value using SPLIT() from a string to an array.
Transpose the array using TRANSPOSE().
Result:
References:
TEXTJOIN
REGEXREPLACE
SPLIT
TRANSPOSE
If I misunderstood your question and this was not the result you want, I apologize.
you can build on it like:
=ARRAYFORMULA(ARRAY_CONSTRAIN(TRANSPOSE(SPLIT(QUERY(TRANSPOSE(QUERY(TRANSPOSE(
IF(A:D="", CHAR(9), A:D)),,9^9)),,9^9), " ")), ROWS(A:A), 1))

extract "N" sized sequences from an array in R

Suppose I have the following array:
a <- sample(letters,100,replace=TRUE)
Then suppose those letters are ordered in a sequence, I want to extract all possible 'n' sized sequences from that array. For example:
For n=2 I would do: paste0(a[1:99],"->",a[2:100])
for n=3 I would do: paste0(a[1:98],"->",a[2:99],"->",a[3:100])
you get the point. Now, my goal is to create a function that would take as input n and would give me back the corresponding set of sequences of the given length from array a
I was able to do it using loops and all that but I was hoping for a high performance one liner.
I am a bit new to R so I'm not aware of all existing functions.
You can use embed. For embed(a, 3), this gives a matrix with columns
a[3:100]
a[2:99]
a[1:98]
in that order.
To reverse the column order use matrix syntax m[rows, cols]:
res = embed(a, 3)[, 3:1]
If you want arrows printed between the columns, then
do.call(paste, c(split(res, col(res)), sep = " -> "))
is one way. This is probably better than apply(res, 1, something), performance-wise, since this is vectorized while apply would loop over rows.
As pointed out by #DavidArenburg, this can similarly be done with data.table:
library(data.table)
do.call(paste, c(shift(a, 2:0), sep = " -> "))[-(1:2)]
shift is like embed, except it ...
returns a list instead of a matrix, so we don't need to split by col to paste
pads with missing values to keep the full length, so we need to drop with -(1:2)
I was hoping to say something useful about how to find obscure functions in R, but came up mostly blank on how embed might be found. Maybe...
Go to any HTML help page
Click the "Index" hyperlink at the bottom
Read every single page
?

Excel: How to use an Array to concatenate strings that are next to a criteread section (If function)

Good Day Everyone
I have an Excel sheet as bellow in two columns. I know how to use an array if function with sum to add up all values next to a column that has met the criterea as in {=sum(if(A1:A5="YES",B1:B5)} but how to go about doing it with strings and concatenate so that they show the result as below
Thanks for Any Help
The Excel array
Edit: I know there is a easy VBA solution, but was wondering if there is an excell way since there is an easy solution if it was values and not strings.
If I'm assuming you don't want the relatively easy VBA solution where you recurse through the initial list and concatenate the answers then you could put the following into B8:
=IFERROR(INDEX(Sheet1!$A$1:$A$6,SMALL(IF(Sheet1!$B$1:$B$6=$A8,ROW(Sheet1!$B$1:$B$6)-ROW(Sheet1!$B$1)+1),COLUMNS($B1:B1))),"")
You'd have to drag it across as it'll put them in separate columns but then you should be able to concatenate them into a single column afterwards.
You have to have Ctrl and Shift held down when inputting as it's an array formula.
Activate iteration in the options. The maximum number of iterations must be equal to or greater than the number of lines.
Add =IF(D1=100;1;D1+1) to cell D1
This is the formula in cell E1 for the Stark houses:
=IF(D1=1;"";IF(D1-1>COUNTIF(B:B;"Stark");E1;E1&INDEX(A$1:A$100;SMALL(IF(B$1:B$100="Stark";ROW($1:$100));D1-1))))
(I hope that I got the English names of the functions correctly.)
I missed one information: You must enter the function as an array function.
Thanks go to http://www.excelformeln.de/formeln.html?welcher=155
Was really Strugling to get it right and eventualy got an answer from a stackoverflow question on how to concatenate whole columns.
Sorted the data via B and then used =TRANSPOSE(A4:A6)
Then Used F9 on the function to get this line ={"Mansion1","Mansion 2","House 3"}
Copied and Concatenate and just remove the {
But this was not ideal as the data set I want to use this on is 2500+ lines :(
Manualy did it though :( :( but will try the above answers for future use.

Resources