当我对未排序数据执行数据透视表列时,它工作正常,但是,当我对排序数据(相同数据)执行操作时,我收到以下错误。
知道如何解决问题会非常有帮助。数据已完整,没有出现错误的空白。
我的代码是:
#"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value",{{"start_date", type date}, {"Surface Date", type date}}),
#"Sorted Rows" = Table.Sort(#"Changed Type1",{{"Surface Date", Order.Ascending}}),
#"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Sorted Rows", {{"Surface Date", type text}}, "en-US"),
List.Distinct(Table.TransformColumnTypes(#"Sorted Rows", {{"Surface
Date", type text}}, "en-US")[#"Surface Date"]), "Surface Date",
"Answer Count", List.Sum)
我正在使用office 2013 Home and office with query 2.27.4163.242
如果我删除已排序的行步骤,它可以正常运行而无错误。
以下是查询的完整代码:
**let
/* Get parameters for filtering*/
Source = Excel.CurrentWorkbook(){[Name="Acitivity"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Surface Date", type date}, {"user_type", type text}, {"user_id", Int64.Type}, {"Subject", type text}, {"Total Surfaces", Int64.Type}, {"Answer Count", Int64.Type}, {"Surf", Int64.Type}, {"PrimaryBoard", type logical}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type",{"user_id"},EAsList,{"user_id"},"NewColumn",JoinKind.Inner),
#"Reordered Columns" = Table.ReorderColumns(#"Merged Queries",{"Surface Date", "user_type", "user_id", "NewColumn", "Subject", "Total Surfaces", "Answer Count", "Surf", "PrimaryBoard"}),
#"Expanded NewColumn" = Table.ExpandTableColumn(#"Reordered Columns", "NewColumn", {"start_date", "Name", "Email", "RevokeDate"}, {"start_date", "Name", "Email", "RevokeDate"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded NewColumn",{"Subject", "Total Surfaces", "Surf", "PrimaryBoard"}),
#"Appended Query" = Table.Combine({#"Removed Columns",NewEAsForAppending}),
#"Removed Columns1" = Table.RemoveColumns(#"Appended Query",{"Subject"}),
#"Replaced Value" = Table.ReplaceValue(#"Removed Columns1",0,null,Replacer.ReplaceValue,{"Answer Count"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value",{{"start_date", type date}, {"Surface Date", type date}}),
#"Sorted Rows" = Table.Sort(#"Changed Type1",{{"Surface Date", Order.Ascending}}),
#"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Sorted Rows", {{"Surface Date", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Sorted Rows", {{"Surface Date", type text}}, "en-US")[#"Surface Date"]), "Surface Date", "Answer Count", List.Sum)
in
#"Pivoted Column"**
使用虚拟数据复制文件很困难,因此无法上传文件。
答案 0 :(得分:0)
您可以为透视列动态创建sort-order-argument,如下所示:
NewOrder= Text.Split (Text.Combine ({"user_type", "user_id", "NewColumn", "Subject", "Total Surfaces", "Answer Count", "Surf", "PrimaryBoard"}, "-") &"-"& Text.Combine(List.Transform(#"Sorted Rows"[Surface Date], each Text.From(_)), "-"), "-")
您可能需要将上面的字段名称调整为实际保留在数据透视中的字段名称。此步骤接收已排序的列,将其转换为文本,然后将其拆分为单个单词。然后将它们与数据透视表中的其余字段名称组合,然后重新排列为列表格式(需要传递给Table.ReorderColumns命令)
然后,您将参考您的步骤" Pivoted Column"步骤#"改变Type1"相反:
#"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Changed Type1", {{"Surface Date", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Changed Type1", {{"Surface Date", type text}}, "en-US")[#"Surface Date"]), "Surface Date", "Answer Count", List.Sum)
并执行排序作为最后一步:
= Table.ReorderColumns(#"Pivoted Column", NewOrder)
答案 1 :(得分:0)
如果您将表格填入Excel,您是否会收到任何有错误的行?出于性能原因,Power Query将仅在查询编辑器预览中执行有限行数的计算。排序可能会使问题更接近表格的顶部,这可以解释为什么在这种情况下你只能看到错误。
答案 2 :(得分:0)
创建了一个新的excel文件,并按照上面相同的步骤进行操作。可能只是一些错误。