【发布时间】:2016-12-23 11:48:27
【问题描述】:
我想按一系列值过滤 Power Query 列。我看到我可以手动选择或取消选择列中的值,但我需要在工作表中已有的一系列值上自动执行此操作。
假设我要查询的表包含 100 个唯一名称。我只想导入与工作表中包含 20 个名称的列表匹配的行。
如何使用 Power Query 做到这一点?
编辑:我可以创建一个 Excel 函数,将名称列表连接成查询所需的格式,如下所示:(= Table.SelectRows(#"Changed Type", each ([Ticket Assignee] ="Name 1" or [Ticket Assignee] ="Name 2")))。但仍然需要一种从查询中引用它的方法。
编辑2:
我的查询:
这个错误是:
Expression.Error:我们需要一个 FieldsSelector 值。
let
names_Source = Excel.CurrentWorkbook(){[Name="namesTable"]}[Content],
names_Values = names_Source{1},
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type datetime}, {"Ticket Assignee", type text}, {"# Solved", Int64.Type}}),
#"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Ticket Assignee] <> null)),
#"Filtered Rows1" = Table.SelectRows(#"Changed Type", each Record.HasFields(names_Values, [Ticket Assignee]))
in
#"Filtered Rows1"
Edit3:修改后的查询:
Expression.Error:我们无法将 null 值转换为 Record 类型。 细节: 价值= 类型=类型
let
names_Source = Excel.CurrentWorkbook(){[Name="namesTable"]}[Content],
names_Values = Record.FromList(names_Source[Zendesk Name], names_Source[Zendesk Name]),
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type datetime}, {"Ticket Assignee", type text}, {"# Solved", Int64.Type}}),
#"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Ticket Assignee] <> null)),
#"Filtered Rows1" = Table.SelectRows(#"Filtered Rows", each Record.HasFields(names_Values, [Ticket Assignee]))
in
#"Filtered Rows1"
Edit4:我的表有空值,错误为空。我添加了一行来过滤掉我的名字源中的空值
【问题讨论】:
-
不要使用
names_Values = names_Source{1},而是使用names_Value = Record.FromList(names_Source[Column1], names_Source[Column1])。您收到 FieldSelector 错误,因为#"Filtered Rows1"引用了错误的表:您要过滤#"Filtered Rows",而不是#"Changed Type" -
@AlejandroLopez-Lago-MSFT 啊,字段选择器不错。我已经按照您的要求进行了更改,现在我收到了第二个错误,
We cannot convert the value null to type Text.。有没有办法调试查询以查看确切的故障点或故障域?再次感谢您的帮助。
标签: excel powerquery