首页 > 解决方案 > 从在不同列 Power BI 或 Excel 中具有多行的列中移动多个值

问题描述

我想从一列中移动数据,该列在行中具有不同的值,但另一列在行中具有相同的值,如 pitcure 所示。 

我是 Power BI 的新手,有人可以帮忙吗?

先感谢您

请求

标签: powerbipowerbi-desktop

解决方案


在 Power BI 中,您可以在Power Query 编辑器中执行一些转换以实现所需的输出。

,您的表结构和示例数据如下所示 -

在此处输入图像描述

现在,转到您的表格的高级编辑器并将代码替换为以下代码 -

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("PcdJDoAgEETRu/TaSyCoKDjPEu5/Dbs0qcVP/ktJjBTitENy8avSTqrWLqrRbsprz6dSr9WMITuwJANoyQg6sgcrcgDrj1Z3BBtyAj05gy25gB25goHcwEjuYC85vw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [col1 = _t, col2 = _t, col3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"col1", type text}, {"col2", type text}, {"col3", type text}}),
    
    //--New Transformation starts from here
    #"Grouped Rows" = Table.Group(#"Changed Type", {"col1"}, {{"grouped", each _, type table [col1=nullable text, col2=nullable text, col3=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each [grouped][col2]),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each [grouped][col3]),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom1", {"Custom", each Text.Combine(List.Transform(_, Text.From), ";"), type text}),
    #"Extracted Values1" = Table.TransformColumns(#"Extracted Values", {"Custom.1", each Text.Combine(List.Transform(_, Text.From), ";"), type text}),
    #"Removed Columns" = Table.RemoveColumns(#"Extracted Values1",{"grouped"})
in
    #"Removed Columns"

这是最终的输出 -

在此处输入图像描述


推荐阅读