Forum Discussion
hamahilal
Jan 31, 2023Copper Contributor
selecting specific characters (3capital letters and 4numbers from a row field in a column
Dear,
I have an renumbers only from a request how to split a specific combination of 3capital letters and 4numbers from a columns below written in red color:
2G/HUAWEI/Region5/Samawa/BSAMH01/Warkaa_SAM3994-2
2G/HUAWEI/Region5/Samawa/BSAMH01/Warkaa_SAM3994-3
2G/HUAWEI/Region5/Samawa/BSAMH01/Warkaa_SAM3994-5
2G/HUAWEI/Region5/Samawa/BSAMH01/Warkaa_SAM3994-6
2G/HUAWEI/Region5/Samawa/BSAMH01/Warkaa_SAM3994-7
2G/HUAWEI/Region5/Emarah/BEMAH02/Wshohadaa_EMA5351-1
2G/HUAWEI/Region5/Emarah/BEMAH02/Wshohadaa_EMA5351-2
2G/HUAWEI/Region5/Emarah/BEMAH02/Wshohadaa_EMA5351-3
2G/HUAWEI/Region5/Emarah/BEMAH02/Wshohadaa_EMA5351-7
NOTE:
1. there are no limit for the characters before the highlighted characters or sometimes after it.
2. The column may be too long as 1000000 records (fields or rows)
3. I need the resolve ASAP please
4. I tried many solutions over internet and YouTube without any results.
- PeterBartholomew1Silver Contributor
Power Query
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{{"Data", type text}}), #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type", "Data", Splitter.SplitTextByEachDelimiter({"_"}, QuoteStyle.Csv, true), {"Data.1", "Data.2"}), #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Data.1", type text}, {"Data.2", type text}}), #"Split Column by Delimiter1" = Table.SplitColumn(#"Changed Type1", "Data.2", Splitter.SplitTextByEachDelimiter({"-"}, QuoteStyle.Csv, false), {"RedString", "Data.2.2"}), #"Removed Other Columns" = Table.SelectColumns(#"Split Column by Delimiter1",{"RedString"}) in #"Removed Other Columns"
- hamahilalCopper Contributor
https://docs.google.com/spreadsheets/d/1HY2AHOEFPZLYnJP4Vm8E47W_4Gcd0ZmS/edit?usp=share_link&ouid=109930702746120690068&rtpof=true&sd=truePeterBartholomew1
dear Mr. Peter
I do appreciated your work but after some editing to what you sent i got after loading the data to a table on the workbook (as you know filtering of result in power query will show not more than 1000 record) so when filtering the table will show individual numbers from 1-7 and A3 and three null (blank) records and for extra note i shall sent you the excel file containing the excel sheet to try you solution on it and send me back your new solution according to live result as you will see.
many thanks for your support in advance
- PeterBartholomew1Silver Contributor
It turns out that 233 records did not contain the pattern of a final underscore followed by a hyphen that I was looking for. The options are to clean the data or look for a more general set of search criteria, possibly involving Regular Expressions.
- PeterBartholomew1Silver Contributor
For the pattern you show the Excel formula can be extracted with the formula
= TEXTBEFORE( TEXTAFTER(data,"_"), "-")
That could be placed within a Lambda function to read
= RedString(data)
where a meaningful name for whatever it is that you have extracted would be used in place of 'RedString'.
If you are importing the data then Power Query would allow you to build a more meaningful data table before it appears in Excel.