How to Split the value and find the longest text string in google sheet - google-apps-script

I have a column in google sheet in which each cell contains this type of text
manager, finance manager
accountant
accountant, chief accountant
manager, auditor, other, finance manager
accountant
I want to find the longest text like below and show that text into new cell
finance manager
accountant
chief accountant
finance manager
accountant
I used split function to split the text and find function but finding character or number of character is working but i am unable to understand how i will get whole longest word
Kindly help me.

An alternative would be to use
=FILTER(TRIM(SPLIT(A1, ",")), LEN(SPLIT(A1, ",")) = MAX(LEN(SPLIT(A1, ","))))
and fill down as far as needed.

Suppose your comma-separated lists reside in A2:A. Place the following in, say, B2 of an otherwise empty range B2:B ...
=ArrayFormula(IF(A2:A="",,TRIM(REGEXEXTRACT(A2:A,"[^,]{"&REGEXEXTRACT(TRIM(TRANSPOSE(QUERY(TRANSPOSE(IF(REGEXMATCH(A2:A,"[^,]{"&SEQUENCE(1,30,30,-1)&"}")=FALSE,,SEQUENCE(1,30,30,-1))),,30))),"\S+")*1&"}"))))
This is a complex formula, one that would be difficult to explain. So I will leave it to you (and others who may be interested) to dissect, analyze and understand the inner workings. However, if there is a specific question I can answer should you (or others) get stuck, feel free to ask.
In short, the formula checks to see if there are any REGEX matches for non-comma groupings of 30 characters in length, then 29, 28 and so on to 1. If so, that number is returned in a space-separated list. The first number (which will be the highest) is returned and used to extract a non-comma REGEX expression of that exact length (which then has any leading or trailing spaces removed from it).

if your text is stored in column A, you can use this formula:
=hlookup(max(arrayformula(len(trim(split(A1,","))))), {arrayformula(len(trim(split(A1,","))));arrayformula(trim(split(A1,",")))},2,False)
Second option is to write a custom function.

Related

Is there a way to use one worksheet as database to create a code based on the date?

I am currently working on a spreadsheet formula where 2 different codes would be generated. Here is the algorithm for the "code" to start with., but I don't know how to construct a proper excel function for it.
There are 10 digits to the code where the first 8 digits are just the date i.e. 20210328_ _
The final 2 digits are dependent on the previous records whether there are records with the same date. If so it would assign a two-digit number starting from 1 to differentiate the different records.
I have tried to use the below formula to achieve what I want but the part where it references the other spreadsheet is bothering me as I need it to be a flexible value where the value is referring to the last row of the spreadsheet. Is there a way to work around this without scripts? I am planning to deploy it on Google Sheets so App scripts solutions would also be workable but not preferable.
=IF(DAY(B2)=RIGHT(Data!A114,2),Data!A114+1,CONCATENATE(YEAR(TODAY()),TEXT(B2,"MM"),DAY(TODAY()),"01"))
FYI B2 is the date of input and Data!A114 is the part where I concern.
Here's what I came up with.
Formula(D3)=IF((TO_PURE_NUMBER(Concatenate(YEAR(A3), TEXT(A3,"MM"),DAY(A3))) - TO_PURE_NUMBER(Concatenate(YEAR(A2),TEXT(A2,"MM"),DAY(A2)))), (TO_PURE_NUMBER(CONCATENATE(TO_PURE_NUMBER(Concatenate(YEAR(A3), TEXT(A3,"MM"),DAY(A3))), "00"))) ,(D2+1))
The data for the dates starts in A3, and continues down.
Link to the Google Sheet I tried it on.
https://docs.google.com/spreadsheets/d/1bwukKFaEow4PysqcJLA9jqjKBLZcY8T1vTN5VpZo8F8/edit?usp=sharing
Let me know if this worked.

How can I group data by matching identical cells in same column then counting instances of a related column?

data output
I am pretty new to Webi and am having an issue creating a variable. I'm trying to check if there is more than 1 email address for each entity legacy account number and if 1 of the contact names contains "Annual Report". So when I flag each entity legacy account number for no email only the ones without a contact name that contains "Annual Report" will be pulled. In the example above only the yellow groups should be called no email. Right now all of them are being pulled into no email. I have tried using if and match as those are what I am most familiar with. Does anyone have any suggestions?
There are number of ways you could do this. I am going to give an example using two variables, but you could easily combine them into one.
Has No Email Var=If(Match(Upper([Contact EmailAddress]); "NOEMAIL*"); 1; 0)
Annual Report Contact Name Var=If(Match(Upper([Contact Name]); "ANNUAL REPORT*"); 1; 0)
Then you would apply a report filter with two components...
Has No Email Var = 1
AND
Annual Report Contact Name Var = 0
Let me explain a few things...
The purpose of the Upper function is the Match function is case sensitive. If you know your email address are always lower case then you could remove that the Upper function and have it match on "noemail*".
It is significant that I only have a asterisk ("*") at the end of the string being sought. That will only find a match where the corresponding column value starts with that string. If you want it to be true whenever the string is found anywhere in the column being searched you would be asterisks on both ends.
You could also put limiting criteria in your query filter. But here is where thing can get confusing. Within the query filter you can choose the Matches pattern operator. However, the wildcard character is different ("%" rather than "*") and you do not put double-quotes around your search text. So you would have some thing like this...
Contact EmailAddress Matches pattern noemail%
AND
Contact Name Different from pattern Annual Report%
I am sure you noticed I didn't convert the search text to uppercase. In the Query Panel Web Intelligence is case-insensitive and would likely follow the case-sensitivity of the database of the source data. All of our databases are case-insensitive so if yours is case-sensitive you may need to play around this this a bit. Or just go with the approach of creating the variables and report filters as I initially laid out.
If you want a wildcard for a single character rather than multiple characters (which is what "*" and "%" will do) you need to use a "?" within your variable definition or a "_" in your query filter.
Hope this helps,
Noel

Capitalize Just the last Letter in string - MS Access

I have a column in my access database table, I ran a query to make it proper case by using StrConv([MyColumn],3) but last two letters are state names and this query makes SOmeThing, soMethINg, NY to Something, Something, Ny,
I want the result as Something, Something, NY
Is there a another query I can run after to capitalize last letter?
You can use:
UcaseLast: Left([YourColumn], Len([YourColumn]) - 1) & UCase(Right([YourColumn], 1))
Well, most people would tell you to store your 'address', 'city', and 'state' as separate fields. Then you Proper Case each separately and concatenate them together. If you can do that... that is your best approach.
If this is a database or file that's been tossed at you and you can't make the field/table changes... it's still possible to get your desired results. However, you better make sure all strings end with your state code. Also make sure you don't have foreign addresses since Canadian (and other countries) use more that two letters for the province code at the end.
But if you are sure all records contain two letter state abbreviations, you can continue with the following:
MyColumnAdj: StrConv(Mid([MyColumn],1,len([MyColumn])-2),3) + StrConv(right([MyColumn],2),1)
This takes the midstring of your [MyColumn] from position 1 to the length of your [MyColumn] minus 2 (leaving off the state code) and it Proper Case's it all.
It then concatenates (using the plus sign) to a rightstring of [MyColumn] for a length of 2 and Upper Case's it.
Once again, this is dangerous if the field doesn't have the State Code consistently at the end of the string.
Best of luck. Hope this helps. :)

Extracting words from a paragraph and then match with existing database by Ms Access

I am the beginner on the usage of MS Access.
I am going to build a program in the MS Access 2007 which can scanning some specific wordings listed in the data table from a paragraph.
For example, I want to know the occurrences of the transportation taken by the students.
(i) Therefore, I set the words "school" and "Bus" in my datatable [tableA] fields [trans].
(ii) Then, I input "I go to school by bus." in the [Input] boxes.
(iii) The result i want is that the sun of occurrences of both "school" and "Bus" can be showed in the another one textbox.
In the current situation, i just create a query [QueryA] from the [tableA] and directly use the count function in the query form. And then set the criteria as " Like [forms]![tableA]![Input] & "*" ".
However, it can just match the words in the [Input] with the final count result of the Query.
Ths a lot for providing any advice, including new direction.
I hope I understand what you're asking here, so I'll give it a stab with the information that you've provided. In your SQL window, try the following script: NOTE: You will need to change the WHERE clause to reflect your Input box(s)
SELECT Count(*) AS Expr1
FROM tableA
WHERE tableA.[trans] Like '%[Input]%;

SSRS - Expression to replace all but last four characters?

Apologies in advance if question is too basic. I searched but couldn't find anything specifically applicable to reporting services.
I'm working on a report that's currently returning the full value that's being queried.
Currently, the expression for that text field is
=Fields!VarName.Value
What I'm looking to do is return only the last four with a set of *s to represent whatever the preceding digits are. Even though the number of digits is going to vary, it's not important that I match digit for digit, so I'm fine with just inserting a set number of *s and then the last four. I figured this would be easier. I've tried this:
="*****" & Right(Fields!VarName.Value,4)
That returns the stars, but not the actual values. Am I just completely off the mark on how to get those last four numbers?
"Right(RTRIM(Fields!VarName.Value),4)" Was the correct answer.