在 PowerBI 中拆分文本列

Split text column in PowerBI

大家好,我有一列如图中的文本,对于每次出现的“|-Starting”子字符串,如何将这种类型的列拆分为多列?

  • 创建一个“grouper”列来对不同的行集进行分组
  • 然后分组
    • 将每个子组拆分为列
    • 转置结果

例如

let
    Source = Excel.CurrentWorkbook(){[Name="Table16"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),

//create a "grouper" column
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "grouper", each if [Column1] = "|-Starting" then [Index] else null),
    #"Filled Down" = Table.FillDown(#"Added Custom",{"grouper"}),

//group the rows creating a delimiter separated string
//  and a counter to obtain the number of columns for the "Split"
    #"Grouped Rows" = Table.Group(#"Filled Down", {"grouper"}, {
        {"group", each Text.Combine([Column1],";"),type text},
        {"numInGroup", each Table.RowCount(_)}
        }),

//maximum number of columns in the result
    numCols=List.Max(#"Grouped Rows"[numInGroup]),
    #"Removed Columns" = Table.RemoveColumns(#"Grouped Rows",{"grouper","numInGroup"}),

//split; then transpose
    #"Split Column by Delimiter" = Table.SplitColumn(#"Removed Columns", "group", 
        Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv),numCols),
    #"Transposed Table" = Table.Transpose(#"Split Column by Delimiter")
in
    #"Transposed Table"