Forum Discussion

PowerBI_Query's avatar
PowerBI_Query
Helper II
3 years ago
Solved

Split Two Columns into Rows by their Respective Delimiters.

I need to spilt two columns into rows e.g Heading7 and Heading9. I could do it individually using excel formulas but I need the adjacent rows to be inserted and repeated as shown in the output screenshot. Grey highlight are the repeated rows.

Input

Output

 

Sample Data

Heading1Heading2Heading3Heading4Heading5Heading6Heading7Heading8Heading9Heading10
12345666Demo text1Some text15545567RTNElectric5(q)-I,5(n)-I,5(o)-II,5(e),9(w),9(e)-I,9(e)-IISometext221-Apr-2023; 21-Sep-2025; 21-Sep-2025; 21-Sep-2025; 21-Sep-2025; 21-Sep-2025; 21-Nov-202621-Apr-23
45345667Demo text2Some text25545567GHHMono5(q)-I,5(n)-I,5(o)-II,5(g)Sometext321-Apr-2023; 21-Sep-2025; 21-Sep-2025; 21-Sep-202521-Apr-23
67345668Demo text3Some text35545567IYTTurbine5(q)-I,5(n)-ISometext421-Apr-2023; 21-Sep-202521-Apr-23
78345669Demo text4Some text45545567VRTHydro5(q)-I,5(n)-I,5(o)-IISometext521-Apr-2023; 21-Sep-2025; 21-Sep-202521-Apr-23
  • Kindly Paste this code in your advance editor and check the result.

    let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nZBPC4JAEMW/iuxJQSF3d1ajU1CkhzqUBCFeqiWCck3s37dv1yLGpAgv781jYPi9SVPiU8ZBCEFcMpJHZVXyVvk6LNRRvgMABxCBnubJTOv4IDdVud+YlX1yvNgFO3+a0mZcOm7fvhqRZvG0+HXY3KV6pr43LEqP9igbWDosZGECdA4zdTFBoNuMZG5KONQ1A1yT4pq0UXMSRVqnKlc/Ku4cVId1qtPiFEHNGWJOhjlZgzNeJVqTc7ne5/ITFdHxH3QthiCsGfqYgWMG3mBYzg1DdN+WX5+FSODfPzWxsgc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Heading1 = _t, Heading2 = _t, Heading3 = _t, Heading4 = _t, Heading5 = _t, Heading6 = _t, Heading7 = _t, Heading8 = _t, Heading9 = _t, Heading10 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Heading1", Int64.Type}, {"Heading2", type text}, {"Heading3", type text}, {"Heading4", Int64.Type}, {"Heading5", type text}, {"Heading6", type text}, {"Heading7", type text}, {"Heading8", type text}, {"Heading9", type text}, {"Heading10", type date}}),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Changed Type", {{"Heading7", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Heading7"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Heading7", type text}}),
    #"Split Column by Delimiter1" = Table.ExpandListColumn(Table.TransformColumns(#"Changed Type1", {{"Heading9", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Heading9"),
    #"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter1",{{"Heading9", type date}})
    in
    #"Changed Type2"

     

     

3 Replies

  • KeyurPatel14's avatar
    KeyurPatel14
    Responsive Resident

    Kindly Paste this code in your advance editor and check the result.

    let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nZBPC4JAEMW/iuxJQSF3d1ajU1CkhzqUBCFeqiWCck3s37dv1yLGpAgv781jYPi9SVPiU8ZBCEFcMpJHZVXyVvk6LNRRvgMABxCBnubJTOv4IDdVud+YlX1yvNgFO3+a0mZcOm7fvhqRZvG0+HXY3KV6pr43LEqP9igbWDosZGECdA4zdTFBoNuMZG5KONQ1A1yT4pq0UXMSRVqnKlc/Ku4cVId1qtPiFEHNGWJOhjlZgzNeJVqTc7ne5/ITFdHxH3QthiCsGfqYgWMG3mBYzg1DdN+WX5+FSODfPzWxsgc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Heading1 = _t, Heading2 = _t, Heading3 = _t, Heading4 = _t, Heading5 = _t, Heading6 = _t, Heading7 = _t, Heading8 = _t, Heading9 = _t, Heading10 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Heading1", Int64.Type}, {"Heading2", type text}, {"Heading3", type text}, {"Heading4", Int64.Type}, {"Heading5", type text}, {"Heading6", type text}, {"Heading7", type text}, {"Heading8", type text}, {"Heading9", type text}, {"Heading10", type date}}),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Changed Type", {{"Heading7", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Heading7"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Heading7", type text}}),
    #"Split Column by Delimiter1" = Table.ExpandListColumn(Table.TransformColumns(#"Changed Type1", {{"Heading9", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Heading9"),
    #"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter1",{{"Heading9", type date}})
    in
    #"Changed Type2"

     

     

    • PowerBI_Query's avatar
      PowerBI_Query
      Helper II

      To reuse the code I need to understand this part

      Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv) 

      QuoteStyle.Csv is optional argument? 

      Table.TransformColumns 2nd argument trasformOperations

      let itemType = (type nullable text) meta [Serialized.Text = true]
      in type {itemType}}})

      What is nullable text and meta [Serialized.Text = true] means?

  • KeyurPatel14's avatar
    KeyurPatel14
    Responsive Resident

    If my solution helped you then kindly consider this as a Solution and give a thumbs up.