【问题标题】:Split text column in PowerBI在 PowerBI 中拆分文本列
【发布时间】:2021-12-09 09:22:14
【问题描述】:

大家好,我有一列文本,就像图片中的那样,我如何将这种类型的列拆分为多个列,以便每次出现“|-Starting”子字符串?

【问题讨论】:

  • 你的结果输出应该是什么?
  • 一个表,每个“|-starting”子字符串有一列,下一个“-starting”点的基础行

标签: text split powerbi powerquery m


【解决方案1】:
  • 创建一个“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"

【讨论】:

  • 这个很好,我测试过,但它不起作用
  • @lucacanonico 不起作用 不是有用的信息。显然它在这里工作。发生了什么?错误信息?结果错误?还有什么?由于我无法将您的屏幕截图粘贴到表格中,我的数据假设与您的数据之间有什么相关差异可能导致它变为not work?您的数据中有分号吗?如果是这样,只需将分隔符更改为实际数据中不存在的内容即可。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-11
  • 1970-01-01
相关资源
最近更新 更多