Extract part of a string in excel - excel

String:
"Department=Acc:2";"Classes=Accessoire";"Suppliers=xxx23";"Category=Décor";"Discount=no";Related_Carousel_Products=[23043]";"Accessory Type=Crinolines et Shorts";
My excel cells are filled with data like this and I want to extract a specific part of it, for example I would like to extract Accessory Type="Crinoline" into a new column so that I can edit them separately. I've tried this article it has many creative ways to extract the data but I cannot find a way to extract in the way I want, I want to extract part of the string, including the quotes.
https://www.extendoffice.com/documents/excel/3639-excel-extract-part-of-string.html

UPDATED - screenshot showing breakdown of each key function
You can do this using mid + search as follows (screenshot below/this sheet refer):
=MID(B2,SEARCH($F$2,B2),SEARCH(";",MID(B2,SEARCH($F$2,B2)+1,LEN(B2))))
where:
B2: the raw text
F2 = 'Accessory Type' (or any other thing you specify that satisfies final bullet)
Entire string you want to return (with or without quotation marks) falls after 'Accessory Type' and before the very next semi-colon (;) - per your example/below screenshot/above link.
How does this work?
We need to find the part of text that starts with the selected word(s) (e.g. "Accessory Type" in this case) and ends after the description of that accessory type (in this case, it's made up "asdfhadhgk")
Working from inside out mid function (A) returns everything after the words "Accessory Type"
Great, now we just need to it 'stop' a bit sooner, i.e. after the semi-colon that first appears after the words Accessory. This is exactly what the outer Mid function (D) achieves (it returns the string starting with "Accessory Type" up to the semi colon)
Screenshots below refer.

Related

Using the replace function in Netsuite for components in assemblies

Very new to Netsuite. I'm trying to use a saved item search to find all instances of {componentitem} entry is 800484 and replace them with component 516551302688
I'm using the REPLACE function in the saved item search but it doesn't like my formula REPLACE(800484, [, 516551302688]){componentitem}
I'm sure I am doing something wrong in the formula but unsure what it is.
The function signature for REPLACE is:
REPLACE(char, search_string, replacement_string)
char is the text to search in.
search_string is the text to search for.
replacement_string is the text to replace the search_string with, where found.
What you have appears to be more like
REPLACE(search_string, replacement_string)char
The text you want to search in is outside of the function altogether (outside the parentheses that enclose what the function will act on). You also have additional brackets and a comma in your formula.
Based you the information in your question, your formula should be
REPLACE({componentitem}, '800484', '516551302688')
I have wrapped the search and replacement strings in quotes as REPLACE deals with strings. If you leave the quotes off, the database will infer the string values of the numbers given and it will still work, but it's best practice to be explicit.
Note that this will only replace the values within the results of the saved search, and will have no effect on the underlying records. Hopefully you already know this, but I just mention it as the wording of your question makes it appear as if you're expecting it to substitute the actual components.
HTH.

Highlight Specific Word in Associated String and String Variable in Tableau

My goal is to create a highlight function for keywords contained within an associated string, and the overall string variable.
After trying "contains" function, trying variations of the logic contained in these links (1st - https://community.tableau.com/thread/214410, 2nd - https://community.tableau.com/message/846896#846896), and receiving an answer from Tableau Support that they don't know how to highlight keywords contained therein, I wanted to try the Stack OverFlow community before giving up on this one.
To illustrate, below is a table showing my goal with a matrix that contains a keyword and an associated string:
The next shows the ability to select a keyword that is then highlighted within all observations in the string variable:
The closest I have achieved is the following where only the associated string and its entirety are highlighted, as opposed to the broader string variable and just the keyword within the relevant string:
The logic is the following:
Create a parameter for users to enter their search keyword, and create a calculated field to see if the keyword is contained in the Comment field
Create and show a Highlighter for the Comment field.
To use a parameter to call attention to the comment using color:
Create a Parameter called "Search Keyword" with data type string. Select "All" for allowable values.
Create a calculated field called Matches or Color Matches, with the following formula:
CONTAINS([Key Words], [Search Keywords])
OR CONTAINS([Comments], [Search Keywords])
Drag this calculated field onto Color on the Marks card
Right-click the parameter and select "Show Parameter Control
Type the keyword to search and highlight.
To use a Highlighter:
Once the dashboard with keywords and comments has been created, navigate to the options menu for the Comments sheet and select Highlighters > Comments
This now displays a Highlight control which will highlight the row of a comment, instead of changing the text color like the parameter does.
This option will also allow for clicking on keywords, but clicking will only highlight the corresponding comment rather than all comments with the keyword.
As a potential third alternative, if viewers only want to see the matching words and not the entire string, we can modify the parameter method to add an IF statement to the calculated field we created earlier:
IF CONTAINS([Key Words], [Search Keywords])
OR CONTAINS([Comments], [Search Keywords])
THEN [Search Keywords]
END
Do you have any suggestions on how to tweak what I have, or even take a different approach? Any help would be greatly appreciated
As I am sure you know, Tableau is going to colour the entire text string as the CONTAINS condition results in TRUE for the entire string. A different approach could be to restructure your data to a 'long' format with 1 row per word (as below).
Doing this will ensure that Tableau knows each word should be evaluated separately and that the Color Marks Card will partition each word. You can then structure your worksheet like this. To ensure the words are showing in the correct order, you'll need a calculated field to create a unique row (I have called sort_order right("000000" + str([sentence_id]),7) + right("000000" + str([Position]), 7). Note that the Text Marks Card is sorted by sort_order and also that the order in which you drag on/order the Mark Cards is important
The colour_keyword formula then is simply something like [word] = [Keyword Parameter] (maybe check for upper/lowercase variants).
I would recommend maintaining your original table's data structure as well as this 'long table format and link the two datasources via a Relationship (Data > Edit Relationships) and use Dashboard Actions. This would hopefully satisfy your highlight requirements and mean less rework for your other worksheets.
I've published the demo tableau workbook to tableau public here

Extracting text from complex string in excel

The attached image (link: https://i.stack.imgur.com/w0pEw.png) shows a range of cells (B1:B7) from a table I imported from the web. I need a formula that allows me to extract the names from each cell. In this case, my objective is to generate the following list of names, where each name is in its own cell: Erik Karlsson, P.K. Subban, John Tavares, Matthew Tkachuk, Steven Stamkos, Dustin Brown, Shea Weber.
I have been reading about left, right, and mid functions, but I'm confused by the irregular spacing and special characters (i.e. the box with question mark beside some names).
Can anyone help me extract the names? Thanks
Assuming that your cells follow the same format, you can use a variety of text functions to get the name.
This function requires the following format:
Some initial text, followed by
2 new lines in Excel (represented by CHAR(10)
The name, which consists of a first name, a space, then a last name
A second space on the same line as the name, followed by some additional text.
With this format, you can use the following formula (assuming your data is in an Excel table, with the column of initial data named Text):
=MID([#Text],SEARCH(CHAR(10),[#Text],SEARCH(CHAR(10),[#Text])+1)+1,SEARCH(" ",MID([#Text],SEARCH(CHAR(10),[#Text],SEARCH(CHAR(10),[#Text])+1)+1,LEN([#Text])),SEARCH(" ",MID([#Text],SEARCH(CHAR(10),[#Text],SEARCH(CHAR(10),[#Text])+1)+1,LEN([#Text])))+1)-1)
To come up with this formula, we take the following steps:
First, we figure out where the name starts. We know this occurs after the 2 new lines, so we use:
=SEARCH(CHAR(10),[#Text],SEARCH(CHAR(10),[#Text])+1)+1
The inner (occurring second) SEARCH finds the first new line, and the outer (occurring first) finds the 2nd new line.
Now that we have that value, we can use it to determine the rest of the string (after the 2 new lines). Let's say that the previous formula was stored in a table column called Start of Name. The 2nd formula will then be:
=MID([#Text],[#[Start of Name]],LEN([#Text]))
Note that we're using the length of the entire text, which by definition is more than we need. However, that's not an issue, since Excel returns the smaller amount between the last argument to MID and the actual length of the text.
Once we have the text from the start of the name on, we need to calculate the position of the 2nd space (where the name ends). To do that, we need to calculate the position of the first space. This is similar to how we calculated the start of the name earlier (which starts after 2 new lines). The function we need is:
=SEARCH(" ",[#[Rest of String]],SEARCH(" ",[#[Rest of String]])+1)-1
So now, we know where the name starts (after 2 new lines), and where it ends (after the 2nd space). Assuming we have these numbers stored in columns named Start of Name and To Second Space respectively, we can use the following formula to get the name:
=MID([#Text],[#[Start of Name]],[#[To Second Space]])
This is equivalent to the first formula: The difference is that the first formula doesn't use any "helper columns".
Of course, if any cell doesn't match this format, then you'll be out of luck. Using Excel formulas to parse text can be finicky and inflexible. For example, if someone has a middle name, or someone has a initials with spaces (e.g. P.K. Subban was P. K. Subban), or there was a Jr. or something, your job would be a lot harder.
Another alternative is to use regular expressions to get the data you want. I would recommend this thorough answer as a primer. Although you still have the same issues with name formats.
Finally, there's the obligatory Falsehoods Programmers Believe About Names as a warning against assuming any kind of standardized name format.

How to modify numbers at the end of a cell using a formula

I have cells in excel containing data of the form v-1-2-1, v-1-2-10, v-1-2-100. I want to convert it to v-1-2-001, v-1-2-010,v-1-2-100. I have nearly 2000 entries
If all of the data follows the format shown then you could use FIND to return the position of '-'. There will be three instances of this character and you need to find the third one so use the position given by the first instance as the start position parameter of the second FIND and again for the third (essentially nesting FIND). Once you have the position of the third '-' you know where the final set of numbers are (from the returned third position+1 to the LEN of the string) and could use SUBSTITUTE or a combination of other excel string functions to configure the final portion as you need it.
I'm assuming that excel has your data formatted as text.
If you need further assistance I'm happy to knock up the formula in excel but I'm off to work now and won't be able to do so for around 9 hours.
Please try:
=LEFT(A1,6)&TEXT(MID(A1,7,10),"000")

How to find a string within a string

I have the list with like 100,000 site link strings
Each link is unique, but it has consistent ?Item=
Then, it's either nothing or it continues after & symbol.
My question is: How do I pull out the item numbers?
I know replace function can offer similar functionality, but it works with Fixed sizes, in my case string can be different in size.
Link example:
www.site.com?sadfsf?sdfsdf&adfasfd?Item=JGFGGG55555
or
www.site.com?sadfsf?sdfsdf&adfasfd?Item=JGFGGG55555&sdafsdfsdfsdf
In both cases I need to get JGFGGG55555 only
If this always is the last portion of the string, you can use the following:
=MID(A1, FIND("?Item=", A1) + 6, 99)
This assumes:
no item numbers will be over 99 digits.
no additional fields follow the item number.
Edit:
With the update to your question, it is apparent you have some strings with additional data after the ?Item= field. Without using VBA there is not a simple means of using MID and FIND to extract this.
However you could create a column which acts as a placeholder.
For example, create a column using:
=MID(A1,FIND("?Item=",A1)+6,99)
This gets you the following value: JGFGGG55555&sdafsdfsdfsdf
Next, create a column using:
=IF(ISERROR(FIND("&",B2)),B2,LEFT(B2,FIND("&",B2)-1))
This produces: JGFGGG55555 by searching the first value for a & and using the portion before it. If it is not found, the first value is simply repeated.
This formula should work for both the examples given:
=MID(A1,FIND("=",A1),IFERROR(LEN(A1)-FIND("&",A1,FIND("=",A1))-1,LEN(A1)+1-FIND("=",A1)))

Resources