Forum Discussion
How to combine data importing from text
- 3 years ago
Try the following code. Here is what I did:
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], #"Replaced Value" = Table.ReplaceValue(Source,"MSH","***MSH",Replacer.ReplaceText,{"Column1"}), Column1 = Text.Combine(#"Replaced Value"[Column1]), #"Split Text" = List.Select(Text.Split(Column1, "***"), each _ <> ""), #"Converted to Table" = Table.FromList(#"Split Text", Splitter.SplitByNothing(), null, null, ExtraValues.Error) in #"Converted to Table"When you split text, the splitter is removed, so I cannot split by MSH. The first thing I did is replaced MSH with ***MSH. Now I can split later by the *** chars.
The Column1 step combines all of that data into one massive block of text. It needs a list, and the #"Replaced Value"[Column1] returns everything as a list.
Then I use Text.Split and use the *** as my delimiter. I also wrapped that with List.Select() to remove any blank rows. the first row was blank for example.Finally I converted to a table.
This is the result, loaded to Excel
Try the following code. Here is what I did:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Replaced Value" = Table.ReplaceValue(Source,"MSH","***MSH",Replacer.ReplaceText,{"Column1"}),
Column1 = Text.Combine(#"Replaced Value"[Column1]),
#"Split Text" = List.Select(Text.Split(Column1, "***"), each _ <> ""),
#"Converted to Table" = Table.FromList(#"Split Text", Splitter.SplitByNothing(), null, null, ExtraValues.Error)
in
#"Converted to Table"
When you split text, the splitter is removed, so I cannot split by MSH. The first thing I did is replaced MSH with ***MSH. Now I can split later by the *** chars.
The Column1 step combines all of that data into one massive block of text. It needs a list, and the #"Replaced Value"[Column1] returns everything as a list.
Then I use Text.Split and use the *** as my delimiter. I also wrapped that with List.Select() to remove any blank rows. the first row was blank for example.
Finally I converted to a table.
This is the result, loaded to Excel