Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

seperating text to coloumn

I have data in below format .txt file and the file is in fixed width

 


10010101 Treasury Account - N 1101.0000.000.10010101.000.784.0000.0000 (3,366,650,063.01) (6,328,498.00) (3,372,978,561.01)
10010101 Treasury Account - N 1101.0000.000.10010101.000.840.0000.0000 (7,268,587.56) 0.00 (7,268,587.56)

 

I need to connect power bi to the above text file and get the output as below in eight different coloumns

10010101 Treasury Account - N 1101 0000 784  (3,366,650,063.01) (6,328,498.00) (3,372,978,561.01)

 

@sa 

 

Highlighted alternate coloumns in bold 

 

1 ACCEPTED SOLUTION
rohit_singh
Solution Sage
Solution Sage

Hi @Anonymous ,

Please try the following :

1) While loading your text file into Power Query, choose delimiter as "Space" and not fixed width

rohit_singh_0-1654781370118.png


2) Perform the following steps as given below. You can copy and paste the code in a blank query and replace <file_path> with the file path of your file.

 

let
    Source = Csv.Document(File.Contents(<file_path>),[Delimiter=" ", Encoding=1252, QuoteStyle=QuoteStyle.Csv]),
    #"Merged Columns" = Table.CombineColumns(Source,{"Column2", "Column3", "Column4", "Column5"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"),
    #"Inserted First Characters" = Table.AddColumn(#"Merged Columns", "First Characters", each Text.Start([Column6], 9), type text),
    #"Inserted Text Between Delimiters" = Table.AddColumn(#"Inserted First Characters", "Text Between Delimiters", each Text.BetweenDelimiters([Column6], ".", ".", 4, 0), type text),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Inserted Text Between Delimiters", "First Characters", Splitter.SplitTextByDelimiter(".", QuoteStyle.Csv), {"First Characters.1", "First Characters.2"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Split Column by Delimiter",{"Column1", "Merged", "First Characters.1", "First Characters.2", "Text Between Delimiters", "Column6", "Column7", "Column8", "Column9"})
in
    #"Reordered Columns"

 

This will give you the desired output

rohit_singh_1-1654781528055.png

 

Kind regards,

Rohit


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 🙂

View solution in original post

1 REPLY 1
rohit_singh
Solution Sage
Solution Sage

Hi @Anonymous ,

Please try the following :

1) While loading your text file into Power Query, choose delimiter as "Space" and not fixed width

rohit_singh_0-1654781370118.png


2) Perform the following steps as given below. You can copy and paste the code in a blank query and replace <file_path> with the file path of your file.

 

let
    Source = Csv.Document(File.Contents(<file_path>),[Delimiter=" ", Encoding=1252, QuoteStyle=QuoteStyle.Csv]),
    #"Merged Columns" = Table.CombineColumns(Source,{"Column2", "Column3", "Column4", "Column5"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"),
    #"Inserted First Characters" = Table.AddColumn(#"Merged Columns", "First Characters", each Text.Start([Column6], 9), type text),
    #"Inserted Text Between Delimiters" = Table.AddColumn(#"Inserted First Characters", "Text Between Delimiters", each Text.BetweenDelimiters([Column6], ".", ".", 4, 0), type text),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Inserted Text Between Delimiters", "First Characters", Splitter.SplitTextByDelimiter(".", QuoteStyle.Csv), {"First Characters.1", "First Characters.2"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Split Column by Delimiter",{"Column1", "Merged", "First Characters.1", "First Characters.2", "Text Between Delimiters", "Column6", "Column7", "Column8", "Column9"})
in
    #"Reordered Columns"

 

This will give you the desired output

rohit_singh_1-1654781528055.png

 

Kind regards,

Rohit


Please mark this answer as the solution if it resolves your issue.
Appreciate your kudos! 🙂

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors