Forum Discussion

Nantemate's avatar
Nantemate
Regular Visitor
3 years ago
Solved

How to combine data importing from text

I have the longest files of this type of code:   MSH|^~\&|ECWExport|1256895402|TXImmTrac|TxDSHS|20230525082503.125-0500||VXU^V04^VXU_V04|3051312345678082603|P|2.5.1|||ER|AL|||||Z22^CDCPHINVS|152468...
  • edhans's avatar
    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