How do you extract characters from a string? - arrays

I want to send emails from my google sheet. I want the emails to address recipients by their first name or the name they are known by. The following is an example of my data in column A.
I need a formula in column B that extracts the first name from column A but if they are known by a different name, the name in the brackets in column A, then I want that name extracted to column B instead. I have the following formula which works for names in brackets but I need help with the formula to extract the first name when there are no brackets.
=(SPLIT(REGEXEXTRACT(A2,"\((.*)\)"),","))

one-cell solution:
=ARRAYFORMULA(IFNA(IFNA(
REGEXEXTRACT(A2:A, "\((.*)\)"),
REGEXEXTRACT(A2:A, ", (.*)"))))

Try this. In B2, enter this formula:
=iferror(SPLIT(REGEXEXTRACT(A2,"\((.*)\)"),","), mid(A2, find(", ", A2)+2, len(A2)))
Explanation:
The first part is yours:
SPLIT(REGEXEXTRACT(A2,"((.*))"),",")
As you've seen, this returns an #ERROR if the "(" isn't found. So use iferror to wrap that. The second part is returned if there is an error:
=mid(A2, find(", ", A2)+2, len(A2))
The mid() function returns a substring from a string. The first argument is the string that you're looking in, found in A2. Then, The starting position of the substring is the location of ", " (offset by 2), and continues to the end of the string.

Try this. In B1, enter this formula:
={"Salutation";arrayformula(if(A2:A="","",iferror((SPLIT(REGEXEXTRACT(A2:A,"\((.*)\)"),",")),index(split(A2:A," "),,2))))}
Explanation:
The first part is yours: SPLIT(REGEXEXTRACT(A2,"((.*))"),",")
As you've seen, this returns an #ERROR if the "(" isn't found. So use iferror to wrap that. The second part is returned if there is an error: index(split(A2:A," "),,2)
The index() function returns the second column from the split(). The advantage to doing it this way is you will not have to drag formulas down.

Related

Array Formula with 3 IF statements?

I'm using google sheets, and trying to look up the string value in cell A4, check column A of Sheet2 for a matching string, then (once found) return the soonest date in column C where;
Column A matches A4
Column I = TRUE
Column J = blank
The formula I've come up with is this;
=ARRAYFORMULA(MIN(IF((Sheet2!A:A=A5)(Sheet2!I:I=TRUE)(Sheet2!J:J=""),Sheet2!C:C,"")))
which returns the error
invalid call to non-function
My previous formula;
=ARRAYFORMULA(MIN(IF((Sheet2!A:A=A4)*(Sheet2!I:I=TRUE),Sheet2!C:C,"")))
Was returning a date, but I needed to add the additional IF statement to check column J is blank, and that's where I think I'm failing - but I'm not entirely sure why. I've tried
Sheet here with example, feel free to edit;
https://docs.google.com/spreadsheets/d/1kUQ2Ut59VZtKGWwyNCwAilIEWHWSk45HP0u1qMORsRA/edit?usp=sharing
Any help here would be much appreciated.
You may try:
=sortn(filter(Sheet2!C:C,Sheet2!A:A=A4,Sheet2!I:I=TRUE,Sheet2!J:J=""),1,,1,1)
You just need to put the asterisks in like you did with your original formula
=ARRAYFORMULA(MIN(IF((Sheet2!A:A=A5)*(Sheet2!I:I=TRUE) * (Sheet2!J:J=""),Sheet2!C:C,"")))
But also check the locale settings of your sheet because the dates appear to be in DD/MM/YYYY format while the locale is set to US (MM/DD/YYYY).
Or you could try using a query:
=query({Sheet2!A2:A,Sheet2!C2:C,Sheet2!I2:I,Sheet2!J2:J},"select Col1,min(Col2) where Col3=true and Col4 is null group by Col1")

How to remove last character of last row in tmap using Talend?

I am extracting two columns using textractjson and passing it to a tmap component where I am concatenating both of the columns as single one.
Also, I want a comma at the end of each row except the last row.
I am not sure how to do this.
Example:
There are two columns in tmap as input:
FirstName
LastName
In output, I have concatenated them to:
FirstName+LastName+","
The problem is I dont want the comma in the last row.
This depends on your job layout and input structure.
You seem to use tExtractJSON, which could mean you get the data from a REST call or out of a database.
Since there is no fixed row amount because of the JSON data structure, you wouldn't be able to use ((Integer)globalMap.get("tFileInputDelimited_1_NB_LINE")). Again, since we don't know your job layout, this depends on it.
If this is not the case, I would count the rows in a tJavaRow component first and then add a second tJavaRow where I'd concat the strings (wouldn't do that in the tMap), but omit the last comma. I'd be able to find the last row with the count I did first. This depends on your Java skills.
You may also concatenate all the rows in a global variable using a tJavaRow, with a comma at the end for each row.
Then, start a new subjob (onSubjobOk) then using a tJava, remove the last character (so the last comma).
Pretty simple, don't have to know how many rows from the input flow but supposing you want the result as a single string (here contained in a global variable).
I might be wrong also. Basically concatenate FirstName and LastName , Create record number column using Numeric.Sequence() function and use one more context variable and store the same sequence number here(it might store last value) also in tJavaRow component.
output_row.name = input_row.FirstName+""+input_row.LastName+","+;
output_row.record_number = Numeric.sequence("recNo", 1, 1);
context.lastNumber = Numeric.sequence("recNo", 1, 1);
create a method in custom java routine.
public static string main _nameChange(String name,Integer record_number){
if(context.lastNumber == record_number){
name = name.substring(0,name.length()-1);
return name;
}
else{
return name;
}
}
Now call _nameChange method within tmap component. Now you can trim the last row's last character.
Ror reference check this

Hide row based on parameter value

How can I simply hide row based on selected parameter in SSRS 2012.
I have LineGuid parameter that has two values: Earthquake and Wind
I want to hide the row if 'Wind' parameter is chosen, because it shows sum value for Earthquake.
So I am entering an Expression in Row Visibility but it gives me an error saying: "Overload resolution failed because no Public '=' can be called..."
I also tried to pass Value(GUID), not Label but gives me the same error.
What am I missing here?
You have the Line GUID parameter set to accept multiple values. The values are passed in as an array which is why you see the String() syntax in the error message. One option is to change that to not accept multiple values. Another option is to use the First selected value like so:
=Parameters!lineGuid.Value(0)
Note the reference to the array index on the end of the expression.
If you want to combine all the values you can also join them like this:
=Join(Parameters!lineGuid.Value, ", ")
This will concatenate the values in the array into a comma separated string.
Join all of your parameters together, then check to see if Wind is part of the string.
= IIF(InStr(Join(Parameters!lineGuid.Label,","),"Wind") > 0,True,False)
In my case I needed to display row when "Earthquake" parameter is chosen, and also when both parameter chosen: Earthquake and Wind.
This expression made it work:
=IIF(InStr(JOIN(Parameters!lineGuid.Label,","),"E")
OR
InStr(JOIN(Parameters!lineGuid.Label,","),"W")
AND
InStr(JOIN(Parameters!lineGuid.Label,","),"E")>0,False,True)
Try use the actually parameter .value not .label name

Calculating a value to use in excel range

I am trying to make an excel template so that when a user copies data into the tab "Account Profile", the last row with contents in it is calculated and this value is used for formulas on other sheets. This formula calculates the last row with data:
=LOOKUP(2,1/('Account Data'!A:A<>""),ROW('Account Data'!A:A))
This works fine, the trouble comes when I try to use the result as a range reference: I want my formulas to iterate from row 2 --> row (value of LOOKUP)
=COUNTIF('Account Data'!$N$2:$N$991,A8)
The "991", I want that replaced with the result of the LOOKUP formula so that the range is always correct. I'm sure there's an easy way but I've tried for a while and can't figure out what the syntax should be.
Scott is right that you should just be using COUNTIF directly with a column reference. However, in case this is a contrived example or something, this is how you'd do it the way you described:
=COUNTIF(INDIRECT("'Account Data'!$N$2:$N$" & LOOKUP(2,1/('Account Data'!A:A<>""), ROW('Account Data'!A:A))), A8)
The important part to look at is INDIRECT("'Account Data'!$N$2:$N$" & LAST_ROW_NUMBER). The INDIRECT function is how you take a string of text and interpret it as a cell reference. The "Some text" & VARIABLE_NAME is how you build such a text string from variables: you use the & symbol to concatenate them.
COUNTIF is not an array formula and as such you can use full column references without detriment.
=COUNTIF('Account Data'!$N:$N,A8)
But if you really want a dynamic range then use INDEX/MATCH:
=COUNTIF('Account Data'!N2:INDEX('Account Data'!N:N,MATCH(1E+99,'Account Data'!A:A)),A8)
This will find the last cell in column A that has a number. If Column A is filled with text then replace 1E+99 with "ZZZ".
If you want to use LOOKUP then:
=COUNTIF('Account Data'!N2:INDEX('Account Data'!N:N,LOOKUP(2,1/('Account Data'!A:A<>""),ROW('Account Data'!A:A))),A8)

return multiple cell values based on string in Google sheets

I have a table with names and corresponding numbers. I want to return the numbers that correspond to ONE name. For this I need to search only in part of the name (string) given in row A (see image below) because some row entries only have 1 name and others have two names.
Table with name and numbers
So for example, I would like to return all the numbers that correspond to "William". I would expect to get the numbers 1 and 3.
In Google Sheets I have tried to use the following FILTER function:
=filter(B2:B7, A2:A7="*"&"William"&"*")
This did not work. It looks like it doesn't like I am using wildcards in my second parameter.
Does anybody have a solution to this?
There isn't a single function which will return a concatenated list of values from an array. But there is a long-winded workaround involving the SEARCH() and CONCATENATE() functions.
Please see example Google sheet
My answer to your specific question is in cell G9 which has the formula =concatenate(G2:G7) and
G2=if(iserr(search("william",A2)),"",B2 & " ")
G3=if(iserr(search("william",A3)),"",B3 & " ")
G4=if(iserr(search("william",A4)),"",B4 & " ")
G5=if(iserr(search("william",A5)),"",B5 & " ")
G6=if(iserr(search("william",A6)),"",B6 & " ")
G7=if(iserr(search("william",A7)),"",B7 & " ")
In the example worksheet I have made it a little more generic using $ syntax so as to allow me to copy the formula in D2 across to fill the range D2:G7 without needing further alteration.
Incidentally, in these situations one often needs to sum up the values, and luckily there is the SUMIF() function for that. See cell G10 for an example =sumif(A2:A7,"*William*",B2:B7) of how to use it.

Resources