我试图在Get & Transform
中复制一些在Excel数据透视表中很容易完成的事情。但是当我尝试透视类别列时,我只得到一行。
原始数据
| Course | Category |
|----------------|----------|
| English | NL |
| Mathematics | CCA |
| Social Studies | STS |
| Social Studies | SS |
| History | STS |
| History | CCA |
| Physics | STS |
| Geology | SS |
| Geology | CCA |
在Excel中,我可以通过拖动轻松生成所需的数据透视表:
但是如果我尝试Get and Transform
中的Pivot Category列,则会创建新列,但会汇总所有计数;不是每门课程的计数。 (如果我选择Don't Aggregate
,我会收到错误。
我做错了什么?
答案 0 :(得分:1)
如
M代码:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{" Course ", type text}, {" Category ", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {" Course "}, {{"Count", each _, type table}}),
#"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {" Course ", " Category "}, {"Count. Course ", "Count. Category "}),
#"Pivoted Column" = Table.Pivot(#"Expanded Count", List.Distinct(#"Expanded Count"[#"Count. Category "]), "Count. Category ", "Count. Course ", List.Count)
in
#"Pivoted Column"
<强>结果:强>
第3步:
第5步: