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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Ivo_T
Regular Visitor

request for transformations for table in text

I woul like to request for help in creating two tables in desirable format ( steps in Power query):

 

1. BUI ( original in plain text) :

Ivo_T_0-1650977195942.png

I need to achieve this view below:

Ivo_T_1-1650977363012.png

The steps which I have to perform in PQ : spereate yellow roww starts with "B" on the left and move rows below start with "R" on the right after I need to fill down the table with yellow rows on the left. 

 

Could you please help. 

B30RR001147SAT1710/17/2020 YD  YesNoNoNoNoNoNoR1472URRRIVER ROAD GARAGE4.37TY00Y
B30RR001147SAT1710/17/2020 YD  YesNoNoNoNoNoNoR1472UCTBSBCANNING TOWN Bus Stn4.55TY04.8Y
B30RR001147SAT1710/17/2020 YD  YesNoNoNoNoNoNoR1472UKHETKEIR HARDIE EST Tarling Rd4.58TY0.470Y

 

Mayny thanks, 

 

Iwona

 

 

 

 

 

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @Ivo_T 

 

If you have only one yellow row, you can try the following code. To use this code, create a blank query, open its Advanced Editor and remove all existing codes there. Paste below code into the window and replace the Folder path with your text file's path. Save the code and you will see the result in below image. 

let
    Source = Table.FromColumns({Lines.FromBinary(File.Contents("C:\Users\Admin\Desktop\Sample.txt"), null, null, 1252)}),
    // select the first row as a table and add an Index column to it
    LeftTable = Table.AddIndexColumn(Table.FirstN(Source,1),"Index",1),
    // select the other rows except the first row as a table and add an Index column to it
    RightTable = Table.AddIndexColumn(Table.Skip(Source,1),"Index",1),
    // merge two tables on Index column with all rows from RightTable
    CombineTable = Table.NestedJoin(LeftTable, {"Index"}, RightTable, {"Index"}, "Table", JoinKind.RightOuter),
    // expand the new "Table" column
    #"Expanded Table" = Table.ExpandTableColumn(CombineTable, "Table", {"Column1"}, {"Column1.1"}),
    // Remove Index column
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Table",{"Index"}),
    // Fill Down Column1
    #"Filled Down" = Table.FillDown(#"Removed Columns",{"Column1"})
in
    #"Filled Down"

vjingzhang_0-1651223496174.png

 

Then split two columns by comma. You will get the expected result you want. 

vjingzhang_1-1651223646330.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

3 REPLIES 3
v-jingzhang
Community Support
Community Support

Hi @Ivo_T 

 

If you have only one yellow row, you can try the following code. To use this code, create a blank query, open its Advanced Editor and remove all existing codes there. Paste below code into the window and replace the Folder path with your text file's path. Save the code and you will see the result in below image. 

let
    Source = Table.FromColumns({Lines.FromBinary(File.Contents("C:\Users\Admin\Desktop\Sample.txt"), null, null, 1252)}),
    // select the first row as a table and add an Index column to it
    LeftTable = Table.AddIndexColumn(Table.FirstN(Source,1),"Index",1),
    // select the other rows except the first row as a table and add an Index column to it
    RightTable = Table.AddIndexColumn(Table.Skip(Source,1),"Index",1),
    // merge two tables on Index column with all rows from RightTable
    CombineTable = Table.NestedJoin(LeftTable, {"Index"}, RightTable, {"Index"}, "Table", JoinKind.RightOuter),
    // expand the new "Table" column
    #"Expanded Table" = Table.ExpandTableColumn(CombineTable, "Table", {"Column1"}, {"Column1.1"}),
    // Remove Index column
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Table",{"Index"}),
    // Fill Down Column1
    #"Filled Down" = Table.FillDown(#"Removed Columns",{"Column1"})
in
    #"Filled Down"

vjingzhang_0-1651223496174.png

 

Then split two columns by comma. You will get the expected result you want. 

vjingzhang_1-1651223646330.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Anonymous
Not applicable

the thing you ask can be done with a group by followed by a merge.

 

but to allow someone to help you, you should publish the source table so that it is copyable.
You should also explain if lines with prefix B and those prefixed R are in different numeor what needs to be done ...

Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors