Forum Discussion
How to extract the data between special characters
- 9 years ago
Ah, so far it wasn't clear to me that you had multiple lines in each text field... at least that's what I understand now.
I created an Excel file with some test data (yours and some slubby examples) and the code below in Power BI - Query Editor and another video to illustrate how it works.
let Source = Excel.Workbook(File.Contents("C:\Users\Marcel\Documents\Forum bijdragen\Power BI Community\How to extract text between special characters.xlsx"), null, true), Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data], #"Changed Type" = Table.TransformColumnTypes(Table1_Table,{{"Comments", type text}}), AddedStart = Table.AddColumn(#"Changed Type", "Start", each Text.PositionOf([Comments],"*",Occurrence.All)), ExpandedStart = Table.ExpandListColumn(AddedStart, "Start"), StartPlus1 = Table.TransformColumns(ExpandedStart, {{"Start", each _ + 1, type number}}), AddedLength = Table.AddColumn(StartPlus1, "Length", each if [Start] = null then null else Text.PositionOf(Text.Range([Comments],[Start]),"&",Occurrence.First)), AddedID = Table.AddColumn(AddedLength, "ID", each if [Start] = null or [Length] = -1 then null else Text.Range([Comments],[Start],[Length])), RemovedOtherColumns = Table.SelectColumns(AddedID,{"ID", "Comments"}), RemovedDuplicates = Table.Distinct(RemovedOtherColumns,{"ID","Comments"}) in RemovedDuplicates
I am trying but didn't get that, could you please attach the GIF file how to do that.
This video explains how to implement the solution proposed by Anonymous.
- MarcelBeug9 years ago
Community Champion
Ah, so far it wasn't clear to me that you had multiple lines in each text field... at least that's what I understand now.
I created an Excel file with some test data (yours and some slubby examples) and the code below in Power BI - Query Editor and another video to illustrate how it works.
let Source = Excel.Workbook(File.Contents("C:\Users\Marcel\Documents\Forum bijdragen\Power BI Community\How to extract text between special characters.xlsx"), null, true), Table1_Table = Source{[Item="Table1",Kind="Table"]}[Data], #"Changed Type" = Table.TransformColumnTypes(Table1_Table,{{"Comments", type text}}), AddedStart = Table.AddColumn(#"Changed Type", "Start", each Text.PositionOf([Comments],"*",Occurrence.All)), ExpandedStart = Table.ExpandListColumn(AddedStart, "Start"), StartPlus1 = Table.TransformColumns(ExpandedStart, {{"Start", each _ + 1, type number}}), AddedLength = Table.AddColumn(StartPlus1, "Length", each if [Start] = null then null else Text.PositionOf(Text.Range([Comments],[Start]),"&",Occurrence.First)), AddedID = Table.AddColumn(AddedLength, "ID", each if [Start] = null or [Length] = -1 then null else Text.Range([Comments],[Start],[Length])), RemovedOtherColumns = Table.SelectColumns(AddedID,{"ID", "Comments"}), RemovedDuplicates = Table.Distinct(RemovedOtherColumns,{"ID","Comments"}) in RemovedDuplicates - Yuvaraj9 years ago
Helper I
thanks Marcel this is what am also expecting:smileyhappy:...
From this i have one doubt in comments are entered single row if the ID are two means it will fetch the first ID row only but i need two ID's.
For Example:
1.Done the CFO data issue increamendal load script wise issue*IM001350816&2.Done the aging no read manufacture code mismatch issue.3.working on GAS ANL enhancement Poc *ALM# 2720&
the above three comments are entered in single row Anonymous provided code is extract the first ID(IM001350816) but I need second ID also(ALM# 2720).
Expecting Output:
ID Comments IM001350816 1.Done the CFO data issue increamendal load script wise issue*IM001350816&
2.Done the aging no read manufacture code mismatch issue.
3.working on GAS ANL enhancement Poc*ALM# 2720&ALM# 2720 1.Done the CFO data issue increamendal load script wise issue*IM001350816&
2.Done the aging no read manufacture code mismatch issue.
3.working on GAS ANL enhancement Poc*ALM# 2720&Regards
Yuvaraj
- Yuvaraj9 years ago
Helper I
Thanks for you valuble time Marcel. I am also expecting this