简体   繁体   English

如何根据表中的一系列值过滤 Power Query?

[英]How to filter Power Query based off of a range of values in a table?

Ok, so I have a range of values that will change every month and I would like to be able to filter a Power Query off of these but can't quite get the code right.好的,所以我有一个每月都会更改的值范围,我希望能够从这些值中过滤掉 Power Query,但不能完全正确地获取代码。 Below is the code I have for pulling the table into Power Query and that works as you can see from the picture below the code.下面是我将表格拉入 Power Query 的代码,正如您从代码下方的图片中看到的那样。 As you can see from that code my table name in Excel is Job and the column I am filtering off of is Order.正如您从该代码中看到的,我在 Excel 中的表名是 Job,我过滤掉的列是 Order。 The second set of code is the code I have to try to filter my query off of this table unsuccessfully thus far.第二组代码是迄今为止我必须尝试从该表中过滤查询失败的代码。 I pasted the entire code for the query but it's really the #"Filtered by Order" line I believe is where the issue is.我粘贴了查询的整个代码,但我认为实际上是 #"Filtered by Order" 行是问题所在。 Any help on getting that code to work would be greatly appreciated.任何有关使该代码正常工作的帮助将不胜感激。

let
Source = Excel.CurrentWorkbook(){[Name="Job"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Order", type text}})
in
#"Changed Type"

在此处输入图片说明

let
Source = Sql.Database("jansql01", "mas500_app"),
dbo_vdvInvoiceLine = Source{[Schema="dbo",Item="vdvInvoiceLine"]}[Data],
#"Removed Other Columns" = Table.SelectColumns(dbo_vdvInvoiceLine,{"Description", "ItemID", "STaxClassID", "ExtAmt", "FreightAmt", "TranID", "TradeDiscAmt", "FormattedGLAcctNo", "Segment1", "Segment2", "Segment3", "SalesOrder", "CustID", "CustName", "TranDate", "PostDate", "City", "StateID", "ItemClassID", "ReleaseSO", "Job Number"}),
#"Filtered by Order" = Table.SelectRows(#"Removed Other Columns", each Table.Contains(Order,[SalesOrder = [Order]])),
#"Added Material Column" = Table.AddColumn(#"Filtered by Order", "Material $", each if [ItemClassID] <> "INSTALLATION" then [ExtAmt] else 0),
#"Added Installation Column" = Table.AddColumn(#"Added Material Column", "Installation $", each if [ItemClassID] = "INSTALLATION" then [ExtAmt] else 0),
#"Merged Queries" = Table.NestedJoin(#"Added Installation Column",{"TranID"},vdvInvoice,{"TranID"},"vdvInvoice",JoinKind.LeftOuter),
#"Expanded vdvInvoice" = Table.ExpandTableColumn(#"Merged Queries", "vdvInvoice", {"STaxAmt"}, {"vdvInvoice.STaxAmt"}),
#"Extracted Date" = Table.TransformColumns(#"Expanded vdvInvoice",{{"TranDate", DateTime.Date, type date}, {"PostDate", DateTime.Date, type date}}),
#"Added Invoice+Tax" = Table.AddColumn(#"Extracted Date", "Invoice+Tax", each [TranID]&Number.ToText([vdvInvoice.STaxAmt])),
#"Sorted Invoice+Tax" = Table.Sort(#"Added Invoice+Tax",{{"Invoice+Tax", Order.Ascending}}),
#"Added Index" = Table.AddIndexColumn(#"Sorted Invoice+Tax", "Index", 0, 1),
#"Added Custom" = Table.AddColumn(#"Added Index", "Invoice+Tax2", each if [Index]=0 then [#"Invoice+Tax"] else if #"Added Index"{[Index]-1}[#"Invoice+Tax"]=[#"Invoice+Tax"] then null else [#"Invoice+Tax"]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"}),
#"Added Tax Column" = Table.AddColumn(#"Removed Columns", "Tax $", each if [#"Invoice+Tax2"] = null then 0 else [vdvInvoice.STaxAmt]),
#"Changed Tax Type" = Table.TransformColumnTypes(#"Added Tax Column",{{"Tax $", type number}}),
#"Added Total Contract" = Table.AddColumn(#"Changed Tax Type", "Total Contract $", each [#"Material $"]+[FreightAmt]+[#"Installation $"]+[#"Tax $"])
in
#"Added Total Contract"

Merge the two queries.合并两个查询。 There are settings in the Merge command that you can click to keep only matching rows.您可以单击合并命令中的设置以仅保留匹配的行。

teylyn's answer is a good and possible approach. teylyn 的回答是一种很好且可行的方法。

Another way to approach this, may be passing the Order numbers of the Job table as a list into the filter argument in the second query:解决此问题的另一种方法可能是将 Job 表的订单号作为列表传递到第二个查询中的过滤器参数中:

Orderlist = Job[Order]
.
.
.
#"Filtered by Order" = Table.SelectRows(#"Removed Other Columns", each List.Contains(Orderlist,[SalesOrder])),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM