Forum Discussion

JB2020's avatar
JB2020
Regular Visitor
6 years ago
Solved

Split one column (mixed titles/data) into two columns

Hi all,   I'm new to PowerQuery and PowerBI, and I've been given a task to set up some data for PowerBI (see image below, first column is our data, second and third are what we need to do with it)....
  • dax's avatar
    6 years ago

    Hi  JB2020,

    You could try below M code

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8i9QitWJVnL2MTQyMcLKNAEzXYNcEUKm6MzgcEcXN4SgGVamKbqZjs6uQIAQNUdREAsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [column1 = _t]),
        #"Added Custom" = Table.AddColumn(Source, "Custom", each if Text.StartsWith([column1],"CL") then [column1] else null),
        #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each if Text.StartsWith([column1],"CL") then null else [column1]),
        #"Filled Down" = Table.FillDown(#"Added Custom1",{"Custom.1"})
    in
        #"Filled Down"

    Best Regards,
    Zoe Zhi

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.