我有一个合并的查询,我需要删除“发票+税”列的重复项,而不必删除该重复项的整个行。我只需要删除该列的重复值。从下图可以看到,我正在尝试从“发票+税”列中删除重复的值。但是我需要保留该行,只是删除重复的值,例如,我在下面突出显示了应删除的内容,未突出显示的任何内容都需要保留。此时,我还将代码包括在图片下面。
let
Order = Order,
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", "UseTaxRate", "ReleaseSO", "Job Number"}),
#"Filtered Rows" = Table.SelectRows(#"Removed Other Columns", each Text.Contains([SalesOrder], Order)),
#"Added Material Column" = Table.AddColumn(#"Filtered Rows", "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]))
in
#"Added Invoice+Tax"
答案 0 :(得分:2)
我想不出这样做的原因,但是如果您真的想,请用下面的两行代替
#"Added Index" = Table.AddIndexColumn(#"Added 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"})
in
#"Removed Columns"
答案 1 :(得分:1)
这是另一种方法,仅此而已:
在您的行#"Added Invoice+Tax" = Table.AddColumn(#"Extracted Date", "Invoice+Tax", each [TranID]&Number.ToText([vdvInvoice.STaxAmt]))
之后,添加逗号,然后代替
in
#"Removed Columns"
添加此内容:
#"Grouped Rows" = Table.Group(#"Added Invoice+Tax", {"Invoice+Tax"}, {{"AllData", each Table.FromColumns({[Installation],[vdvInvoice.STaxAmt],{[#"Invoice+Tax"]{0}}},{"Installation", "vdvInvoice.STaxAmt", "Invoice+Tax"}), type table}}),
#"Removed Other Columns2" = Table.SelectColumns(#"Grouped Rows",{"AllData"}),
#"Expanded AllData" = Table.ExpandTableColumn(#"Removed Other Columns2", "AllData", {"Installation", "vdvInvoice.STaxAmt", "Invoice+Tax"}, {"Installation", "vdvInvoice.STaxAmt", "Invoice+Tax"})
in
#"Expanded AllData"
上面的“ #Grouped Rows”行的作用是按照发票+税收进行分组,并为原始表的各列中的每个发票+税收提供一个子表。但是,在制作每个子表时,从原始表中提取与每个Invoice + Tax关联的 all 安装和vdvInvoice.STaxAmt行,它仅提取与每个Invoice + Tax关联的第一个Invoice + Tax行Table.FromColumns({[Installation],[vdvInvoice.STaxAmt],{[#"Invoice+Tax"]{0}}}...
的基本意思是获取“安装”和“ vdvInvoice.STaxAmt”列中的所有行,并且仅获取列表中的列表项0(第1行),该列表项实际上是“发票+税”列。
完整查询:您在上面提供的带有我的一小部分内容的初始查询为:
let
Order = Order,
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", "UseTaxRate", "ReleaseSO", "Job Number"}),
#"Filtered Rows" = Table.SelectRows(#"Removed Other Columns", each Text.Contains([SalesOrder], Order)),
#"Added Material Column" = Table.AddColumn(#"Filtered Rows", "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])),
#"Grouped Rows" = Table.Group(#"Added Invoice+Tax", {"Invoice+Tax"}, {{"AllData", each Table.FromColumns({[Installation],[vdvInvoice.STaxAmt],{[#"Invoice+Tax"]{0}}},{"Installation", "vdvInvoice.STaxAmt", "Invoice+Tax"}), type table}}),
#"Removed Other Columns2" = Table.SelectColumns(#"Grouped Rows",{"AllData"}),
#"Expanded AllData" = Table.ExpandTableColumn(#"Removed Other Columns2", "AllData", {"Installation", "vdvInvoice.STaxAmt", "Invoice+Tax"}, {"Installation", "vdvInvoice.STaxAmt", "Invoice+Tax"})
in
#"Expanded AllData"