Extract 2 non-consecutive strings and always sort them in desired way - regex

I'm finishing my regex project in google sheets and this last question I have for it. Hope you can help.
I have a column, in which one cell may or may not contain multiple strings.
This is an example of it (start position):
Now I want to extract the following values:
Team (A)
Team B
Team (A) Team B
Desired end result image:
I want to check for all 3 possible values, and always sort them with Team (A) as a priority. In case the initial cell (C column) is empty, the result is empty.
I tried this formula:
=ARRAYFORMULA(IFERROR(REGEXEXTRACT(C2,"Team \(A\)|Team B|[Team \(A\) "&" Team B]"),IF(C2="","")))
Problems I have:
Don't know how to give priority :/
Don't know how to give them sorting order :/
All help welcome, thank you.

=ARRAYFORMULA(REGEXREPLACE(IFERROR(
REGEXEXTRACT(C2:C, "(Team \(A\))")&CHAR(10))&
IFERROR(REGEXEXTRACT(C2:C, "(Team B)")), "\n$", ))

Related

Google Sheets - Issue with IFS statement using OR & AND returning TRUE/FALSE

This is the formula I am currently using:
=IFS(OR($C28="Sergeant First Class",$C28="Master Sergeant",$C28="First Sergeant",$C28="Warrant Officer",$C28="Junior Lieutenant"),AND(COUNTIFS('TRYOUT LOG'!$S:$S,$D28, 'TRYOUT LOG'!$D:$D, "TRUE",'TRYOUT LOG'!$T:$T,$C28),COUNTIFS('TRYOUT LOG'!$H:$H,$D28, 'TRYOUT LOG'!$D:$D, "TRUE",'TRYOUT LOG'!$I:$I,$C28)))
This returns "TRUE", but will return "FALSE" if the criteria isn't met. However, I want it to actually count the amount of times that the criteria is met, rather than just returning TRUE/FALSE.
I'll try to explain what exactly I want the formula to do.
I am currently checking if cell in C28 is a certain text, if they are then to count how many times this criteria appears in the 'TRYOUT LOG' sheet. I want it to check that column S on the Tryout Log matches D28, then for column D on the Tryout Log to match to "TRUE" and then for column T on the Tryout Log to match C28, then count how many that is all correct, and then ALSO (the AND statement) count how many times it appears in the other rows too, matching a similar criteria with just slightly different columns.
Essentially I need it to just check if a cell is = to a certain text, then count how many times 2 similar criterias are matched on the TRYOUT LOG sheet and return that amount.
Hopefully that all makes sense, if not I'm happy to answer any questions.
Any help is appreciated so thank you in advance.
Edited to include viewable link to the sheet
https://docs.google.com/spreadsheets/d/11-KJOgAZZvTO481wbqL1VR8hoSR02vCj-kHrJ619yVM/edit?usp=sharing

How can I extract specific patterns from a string?

I currently have a dataset filled with the following pattern:
My goal is to get each value into a different cell.
I have tried with the following formula, but it's not yielded the results I am looking for.
=SPLIT(D8,"[Stock]",FALSE,FALSE)
I would appreciate any guidance on how I can get to the ideal output, using Google Sheets.
Thank you in advance!
I will assume here from your post that your original data runs D8:D.
If you want to retain [Stock] in each entry, try the following in the Row-8 cell of a column that is otherwise empty from Row 8 downward:
=ArrayFormula(IF(D8:D="",,TRIM(SPLIT(REGEXREPLACE(D8:D&"~","(\[Stock\]).","$1~"),"~",1,1))))
If you don't want to retain [Stock] in each entry, use this version:
=ArrayFormula(IF(D8:D="",,TRIM(SPLIT(REGEXREPLACE(D8:D&"~","\[Stock\].","~"),"~",1,1))))
These formulas don't function based on using any punctuation at all as markers. They also assure that you don't wind up with blank (and therefore unusable) cells interspersed for ending SPLITs.
, only used in the separator
=ARRAYFORMULA(SPLIT(D8:D,", ",FALSE))
, used also in each string ([stock] will be replaced)
=ARRAYFORMULA(SPLIT(D8:D," [Stock], ",FALSE))
, used also in each string ([stock] will not be replaced)
=ArrayFormula(SPLIT(REGEXREPLACE(M9:M11,"(\[Stock\]), ","$1♦"),"♦"))
use:
=INDEX(TRIM(IFNA(SPLIT(D8:D; ","))))

Google Sheets: Multiple "if" and "find" within an Array formula

background info - not important
I realise I need improvement on understanding logic and understanding documentation when playing around with Android apps. So, I thought I'll switch to Google Sheets in the hope of some basic practice in a context I might find easier to understand.
question
I've set up a Google Sheet:
https://docs.google.com/spreadsheets/d/1T7q_CGMFObxS_0DGikUdSdLTf97XmEPXY0S7yItuA5Y/edit?usp=sharing
I would like Column B to:
display "Folder1" if "Black" is found in the adjacent Column A cell.
display "Folder2" if "Blue" is found in the adjacent Column A cell.
display "Folder3" if "Green" is found in the adjacent Column A cell.
and to then be able to add more conditions.
My formula for Column B is currently:
=ARRAYFORMULA(
IFS(
find("Black", A2:A,1)>0,"Folder1",
find("Blue", A2:A,1)>0,"Folder2",
find("Green", A2:A,1)>0,"Folder3")
)
Which is only meeting the first condition "Folder1" if "Black" is found and not continuing with the rest of the if clauses.
I think I have nested it correctly though because all of the IFS() are at the same level with their corresponding find() within. And, I have two closing brackets which close the IFS and the ARRAYFORMULA.
Am I just simply not using the right kind of functions for what I'd like to do?
Thank you for your suggestions on how I can solve this!
The problem is that find() only returns a number > 0 if it actually finds a match. Otherwise it returns an error which you can't test for explicitly.
You can fix you code like this:
=ARRAYFORMULA(
IFS(
isnumber(find("Black", A2:A,1)),"Folder1",
isnumber(find("Blue", A2:A,1)),"Folder2",
isnumber(find("Green", A2:A,1)),"Folder3")
)
Now we can test that what find() returns is an number and the code will work!
Obviously, I put on multiple lines for clarity.

Google Sheets Pattern Matching/RegEx for COUNTIF

The documentation for pattern matching for Google Sheets has not been helpful. I've been reading and searching for a while now and can't find this particular issue. Maybe I'm having a hard time finding the correct terms to search for but here is the problem:
I have several numbers (part numbers) that follow this format: ##-####
Categories can be defined by the part numbers, i.e. 50-03## would be one product category, and the remaining 2 digits are specific for a model.
I've been trying to run this:
=countif(E9:E13,"50-03[123][012]*")
(E9:E13 contains the part number formatted as text. If I format it any other way, the values show up screwed up because Google Sheets thinks I'm writing a date or trying to do arithmetic.)
This returns 0 every time, unless I were to change to:
=countif(E9:E13,"50-03*")
So it seems like wildcards work, but pattern matching does not?
As you identified and Wiktor mentioned COUNTIF only supports wildcards.
There are many ways to do what you want though, to name but 2
=ArrayFormula(SUM(--REGEXMATCH(E9:E13, "50-03[123][012]*")))
=COUNTA(FILTER(E9:E13, REGEXMATCH(E9:E13, "50-03[123][012]*")))
This is a really big hammer for a problem like yours, but you can use QUERY to do something like this:
=QUERY(E9:E13, "select count(E) where E matches '50-03[123][012]' label count(E) ''")
The label bit is to prevent QUERY from adding an automatic header to the count() column.
The nice thing about this approach is that you can pull in other columns, too. Say that over in column H, you have a number of orders for each part. Then, you can take two cells and show both the count of parts and the sum of orders:
=QUERY(E9:H13, "select count(E), sum(H) where E matches '50-03[123][012]' label count(E) '', sum(H) ''")
I routinely find this question on $searchEngine and fail to notice that I linked another question with a similar problem and other relevant answers.

Update vlookup table array

Suppose I have the following vlookup command:
=VLOOKUP('Sheet1'!S2,'Sheet2'!$B$138:$C$145,2,FALSE)
When I drag the vlookup to the right I want it to update to
=VLOOKUP('Sheet1'!S2,'Sheet2'!$B$146:$C$153,2,FALSE)
In other words, I want the letters B and C fixed but the numbers to increment by 8. How would I do this?
It looks like your answer is always in column C and your lookup value in column A. If this is the case use INDEX MATCH
=INDEX ( C:C , MATCH ( 'Sheet1'!S2 , 'Sheet2'!$B:$C , 0 ))
I've made a few assumptions. Drop a pic of your tables and I can amend it if you can't work out which bits to change
That may be possible using some long if-then-else logic or macro but it seems an odd thing to do. The numbers represent rows so if you are incrementing them across columns I wonder whether you need to transpose your data and/or use HLOOKUP instead. There is probably a better way to achieve what you want but it is difficult to answer from the question as provided.