【问题标题】:How to aggregate/group the data from one table and output the result as another table in PowerBI?如何聚合/分组一个表中的数据并将结果输出为 PowerBI 中的另一个表?
【发布时间】:2022-01-05 04:27:26
【问题描述】:

我有一个原始数据表格,如下面的截图所示:

我想将原始数据表中的数据分组到输出表中,如下截图所示:

基本上,输出表是计算不同摄入量中每个理解水平的学生人数。我可以知道如何从原始数据表中获取输出表吗?我还是 Power Query 的新手,任何帮助都将不胜感激!

这是我尝试过的:

代码:

= Table.Group(Source, {"Intake"}, {
        {"Count_Little_Understand", each Table.RowCount(Table.SelectRows(_, each ([Topic 1] = "Little Understanding"))), Int64.Type},
        {"Count_General_Understanding", each Table.RowCount(Table.SelectRows(_, each ([Topic 1] = "General Understanding"))), Int64.Type}, 
        {"Count_Good_Understand", each Table.RowCount(Table.SelectRows(_, each ([Topic 1] = "Good Understanding"))), Int64.Type},
        {"Count_Fully_Understand", each Table.RowCount(Table.SelectRows(_, each ([Topic 1] = "Fully Understand"))), Int64.Type}
    })

我只能按单个主题获取表格,不知道如何包括下面附加的其他主题,以及添加另一个额外的列来标记主题,如我的第二个屏幕截图所示。希望得到一些关于我应该如何修改代码的建议/帮助。谢谢/1

【问题讨论】:

  • 我添加了我在我的问题中尝试过的内容。

标签: datatable powerbi powerquery aggregation


【解决方案1】:

我重建了一个类似但较短的表格:


现在我们首先进入Transform (1),标记主题列(2) 和Unpivot Columns (3)。


您的表格现在看起来像以下屏幕截图。最后,我们选择Value列(1),点击Pivot Column(2),选择Employee Name(3)。


结果:

【讨论】:

    【解决方案2】:

    您可以UnpivotTopic 列,然后PivotUnderstanding 列,使用 Employee NameCount 作为聚合值。

    然后简单地重新排序列和排序行,以适应您需要的输出:

    #"Unpivoted Topic" = Table.UnpivotOtherColumns(#"Raw Data Table", {"Employee Name", "Intake"}, "Topic", "Understanding"),
    #"Pivoted Understanding" = Table.Pivot(#"Unpivoted Topic", List.Distinct(#"Unpivoted Topic"[Understanding]), "Understanding", "Employee Name", List.NonNullCount),
    #"Reordered Columns" = Table.ReorderColumns(#"Pivoted Understanding",{"Intake", "Topic", "Little Understanding", "General Understanding", "Good Understanding", "Fully Understand"}),
    #"Sorted Rows" = Table.Sort(#"Reordered Columns",{{"Topic", Order.Ascending}, {"Intake", Order.Ascending}})
    

    输出:

    【讨论】:

      猜你喜欢
      • 2012-03-04
      • 2018-04-04
      • 2019-08-04
      • 1970-01-01
      • 2014-01-25
      • 2011-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多