Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel powerquerypivot丢失行_Excel_Powerquery - Fatal编程技术网

Excel powerquerypivot丢失行

Excel powerquerypivot丢失行,excel,powerquery,Excel,Powerquery,我试图在Get&Transform中复制一些在excelprovot表中很容易完成的东西。但是当我尝试旋转Category列时,我只得到一行 原始数据 | Course | Category | |----------------|----------| | English | NL | | Mathematics | CCA | | Social Studies | STS | | Social Studies | SS

我试图在
Get&Transform
中复制一些在excelprovot表中很容易完成的东西。但是当我尝试旋转Category列时,我只得到一行

原始数据

| 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
中透视Category列,则会创建新列,但会汇总所有计数;不是每道菜的计数。(如果我选择了
不聚合
,我会得到一个错误

我做错了什么?

例如

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"
结果:

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"

第三步:

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"

第五步:

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"

感谢您的清晰解释。(比旧的透视表方法更复杂,但更灵活)。我无意中发现了Group By,但在UI中找不到扩展。我感觉有一种更整洁的方式,但这是我记忆中的方式。有没有一种方式可以将随机自定义数字格式应用于PQ中的计数?例如;
“X”;
以抑制0,并将正计数显示为XOh,没关系。我找到了
替换值
按钮OK。如果没有,请通知我。