Power BI Power Query filter main table with two tables based on columns from both
Power BI Power Query filter main table with two tables based on columns from both
我有一个 table 发票,必须针对某些供应商和某些帐号进行过滤。必须过滤的供应商和帐号都在两个小 excel 文件中。我如何将它们与主要 table 结合起来,以便针对帐号或供应商编号过滤主要 table?
有几种方法可以做到这一点。这是一个解决方案,它通过分别筛选供应商和帐号来创建两个发票编号列表,然后将它们组合成一个用于筛选主要 table.
的列表
这里是使用的示例 table(全部包含在下面的 M 代码中):
主表
供应商过滤器
帐户过滤器
这是您可以粘贴到空白查询中的 M 代码:
let
// Import sample tables and edit data types if needed
SourceMainTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VY+7DcAgDAV3oabwB4dQZok0EfuvkWcLJNMg3p3Qie8rRFxqYSOcr18fgFldCNYILgdXLOEQeoiG1SlECyFLGJZSSmxxYbWU2Lx7wlJCl7j9QU+JLYb/glNiiUCWEuDzBw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Invoice = _t, Value = _t, Vendor = _t, Account = _t]),
MainTable = Table.TransformColumnTypes(SourceMainTable,{{"Invoice", type text}, {"Value", Int64.Type}, {"Vendor", type text}, {"Account", type text}}),
VendorFilter = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjNWitUBUiZKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Vendor = _t]),
AccountFilter = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjQwVoqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Account = _t]),
// Extract lists of invoice numbers filtered for vendors and for account numbers separately
ListInvoicesFilteredVendors = Table.SelectRows(MainTable, each List.Contains(VendorFilter[Vendor], [Vendor]))[Invoice],
ListInvoicesFilteredAccounts = Table.SelectRows(MainTable, each List.Contains(AccountFilter[Account], [Account]))[Invoice],
// Combine both lists of invoice numbers into one list and use it to filter main table
ListInvoicesCombined = List.Distinct(List.Combine({ListInvoicesFilteredVendors, ListInvoicesFilteredAccounts})),
FilteredTable = Table.SelectRows(MainTable, each List.Contains(ListInvoicesCombined, [Invoice]))
in
FilteredTable
这是结果,您可以看到发票 001、002、005 和 006 不包括在内,因为它们不包含 V3、V4 或 A03:
我有一个 table 发票,必须针对某些供应商和某些帐号进行过滤。必须过滤的供应商和帐号都在两个小 excel 文件中。我如何将它们与主要 table 结合起来,以便针对帐号或供应商编号过滤主要 table?
有几种方法可以做到这一点。这是一个解决方案,它通过分别筛选供应商和帐号来创建两个发票编号列表,然后将它们组合成一个用于筛选主要 table.
的列表这里是使用的示例 table(全部包含在下面的 M 代码中):
主表
供应商过滤器
帐户过滤器
这是您可以粘贴到空白查询中的 M 代码:
let
// Import sample tables and edit data types if needed
SourceMainTable = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("VY+7DcAgDAV3oabwB4dQZok0EfuvkWcLJNMg3p3Qie8rRFxqYSOcr18fgFldCNYILgdXLOEQeoiG1SlECyFLGJZSSmxxYbWU2Lx7wlJCl7j9QU+JLYb/glNiiUCWEuDzBw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Invoice = _t, Value = _t, Vendor = _t, Account = _t]),
MainTable = Table.TransformColumnTypes(SourceMainTable,{{"Invoice", type text}, {"Value", Int64.Type}, {"Vendor", type text}, {"Account", type text}}),
VendorFilter = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjNWitUBUiZKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Vendor = _t]),
AccountFilter = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjQwVoqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Account = _t]),
// Extract lists of invoice numbers filtered for vendors and for account numbers separately
ListInvoicesFilteredVendors = Table.SelectRows(MainTable, each List.Contains(VendorFilter[Vendor], [Vendor]))[Invoice],
ListInvoicesFilteredAccounts = Table.SelectRows(MainTable, each List.Contains(AccountFilter[Account], [Account]))[Invoice],
// Combine both lists of invoice numbers into one list and use it to filter main table
ListInvoicesCombined = List.Distinct(List.Combine({ListInvoicesFilteredVendors, ListInvoicesFilteredAccounts})),
FilteredTable = Table.SelectRows(MainTable, each List.Contains(ListInvoicesCombined, [Invoice]))
in
FilteredTable
这是结果,您可以看到发票 001、002、005 和 006 不包括在内,因为它们不包含 V3、V4 或 A03: