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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
cgkas
Helper V
Helper V

How to split a column in two tables based on row content?

Hi, I have a table like this below

image.png

For which I want to split it in two different tables, the first from row 1 until row before first occurence of "production_options". And next table from first occurence of "production_options" until the end, getting two tables like these ones:

image.png

 

The is the binary input. Thanks in advance.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fY7BCsIwEET/pedQWi149epJ76WENdnSQJINm01Bv96aCnrytLAzvDfj2JiShQKyxgDOq+f53hoKLZRmUltKcXYcQBzFT0O4YM0sJmAJGEVd4krOYK7/VNgskFETW2R1u+r+cBxqJMjBRfBqoSy66067ZJugF/L2yyZ2G7dqVb9TmWwxdQel99llZtBZIHlUM/iM/6ozsUFthp8mlKStX+WRVNdM0ws=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [DATA = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"DATA", type text}})
in
    #"Changed Type"

 

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@cgkas , check out steps in this power query code

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSK1YlWMgKTxmDSBEyagkkzMzAVUJSfUppcEu9fUJKZn1cMFrMAk5Zg0tAAu7JYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
_pos = List.PositionOf(#"Changed Type"[Column1],"Product_Options"),
_firstList = List.FirstN(#"Changed Type"[Column1],_pos+1),
_LastList = List.LastN(#"Changed Type"[Column1],List.Count(#"Changed Type"[Column1])- (_pos+1)),
_final = List.Zip({_firstList,_LastList}),
#"Converted to Table" = Table.FromList(_final, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Extracted Values" = Table.TransformColumns(#"Converted to Table", {"Column1", each Text.Combine(List.Transform(_, Text.From), ";"), type text}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "Column1", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Column1.1", "Column1.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Column1.1", type text}, {"Column1.2", type text}})
in
#"Changed Type1"

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

amitchandak
Super User
Super User

@cgkas , Try this one with your data

 

amitchandak_0-1672452939079.png

 

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fY7BCsIwEET/pedQWi149epJ76WENdnSQJINm01Bv96aCnrytLAzvDfj2JiShQKyxgDOq+f53hoKLZRmUltKcXYcQBzFT0O4YM0sJmAJGEVd4krOYK7/VNgskFETW2R1u+r+cBxqJMjBRfBqoSy66067ZJugF/L2yyZ2G7dqVb9TmWwxdQel99llZtBZIHlUM/iM/6ozsUFthp8mlKStX+WRVNdM0ws=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [DATA = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"DATA", type text}}),
_pos = List.PositionOf(#"Changed Type"[DATA],"production_options"),
_firstList = List.FirstN(#"Changed Type"[DATA],_pos+1),
_LastList = List.LastN(#"Changed Type"[DATA],List.Count(#"Changed Type"[DATA])- (_pos+1)),
_final = List.Zip({_firstList,_LastList}),
#"Converted to Table" = Table.FromList(_final, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Extracted Values" = Table.TransformColumns(#"Converted to Table", {"Column1", each Text.Combine(List.Transform(_, Text.From), ";"), type text}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "Column1", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Column1.1", "Column1.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Column1.1", type text}, {"Column1.2", type text}})
in
#"Changed Type1"

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@cgkas , Try this one with your data

 

amitchandak_0-1672452939079.png

 

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fY7BCsIwEET/pedQWi149epJ76WENdnSQJINm01Bv96aCnrytLAzvDfj2JiShQKyxgDOq+f53hoKLZRmUltKcXYcQBzFT0O4YM0sJmAJGEVd4krOYK7/VNgskFETW2R1u+r+cBxqJMjBRfBqoSy66067ZJugF/L2yyZ2G7dqVb9TmWwxdQel99llZtBZIHlUM/iM/6ozsUFthp8mlKStX+WRVNdM0ws=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [DATA = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"DATA", type text}}),
_pos = List.PositionOf(#"Changed Type"[DATA],"production_options"),
_firstList = List.FirstN(#"Changed Type"[DATA],_pos+1),
_LastList = List.LastN(#"Changed Type"[DATA],List.Count(#"Changed Type"[DATA])- (_pos+1)),
_final = List.Zip({_firstList,_LastList}),
#"Converted to Table" = Table.FromList(_final, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Extracted Values" = Table.TransformColumns(#"Converted to Table", {"Column1", each Text.Combine(List.Transform(_, Text.From), ";"), type text}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "Column1", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Column1.1", "Column1.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Column1.1", type text}, {"Column1.2", type text}})
in
#"Changed Type1"

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak 

 

Thanks for your help. It seems to work fine. One question, how would be if the string searched begins with "production" or contains "production" instead of look for exactly "production_options" in this command? Something like:

 

= List.PositionOf(#"Changed Type"[DATA], CONTAINS<"production">)

 

@cgkas , That add column first that will give 1 and 0 of some flag, and then get the position of in that new column, and the rest of the code will be in the same column

 

if Text.Contains([Column1], "production") then "1"  else "0"

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak Excellent. I was able to get it following your suggestion. Thanks again

amitchandak
Super User
Super User

@cgkas , check out steps in this power query code

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSK1YlWMgKTxmDSBEyagkkzMzAVUJSfUppcEu9fUJKZn1cMFrMAk5Zg0tAAu7JYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
_pos = List.PositionOf(#"Changed Type"[Column1],"Product_Options"),
_firstList = List.FirstN(#"Changed Type"[Column1],_pos+1),
_LastList = List.LastN(#"Changed Type"[Column1],List.Count(#"Changed Type"[Column1])- (_pos+1)),
_final = List.Zip({_firstList,_LastList}),
#"Converted to Table" = Table.FromList(_final, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Extracted Values" = Table.TransformColumns(#"Converted to Table", {"Column1", each Text.Combine(List.Transform(_, Text.From), ";"), type text}),
#"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "Column1", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"Column1.1", "Column1.2"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Column1.1", type text}, {"Column1.2", type text}})
in
#"Changed Type1"

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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