gpt4 book ai didi

powerquery - 扩展表时 Power Query 缺失值

转载 作者:行者123 更新时间:2023-12-04 17:42:11 24 4
gpt4 key购买 nike

我有一个问题:当我尝试从许多文件中扩展表格时,我丢失了一些值。

到目前为止我发现当查询遇到一个空表时问题就开始了。

我已尝试过滤掉空表,但问题仍然存在。

知道什么是问题以及如何解决吗?

enter image description here

查询:

let
Source = Folder.Files("X:\Operations\tutaj\SLA MIAD"),
#"Lowercased Text" = Table.TransformColumns(Source,{{"Extension", Text.Lower, type text}}),
#"Filtered Rows" = Table.SelectRows(#"Lowercased Text", each Text.Contains([Extension], "xlsx")),
#"Filtered Rows1" = Table.SelectRows(#"Filtered Rows", each Text.Contains([Name], "NCR") or Text.Contains([Name], "Printec") or Text.Contains([Name], "PTL")),
#"Filtered Rows2" = Table.SelectRows(#"Filtered Rows1", each Text.Contains([Name], "2018")),
#"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows2",{"Content"}),
#"Added Custom" = Table.AddColumn(#"Removed Other Columns", "Custom", each Excel.Workbook([Content])),
#"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Name", "Data", "Item", "Kind", "Hidden"}, {"Name", "Data", "Item", "Kind", "Hidden"}),
#"Filtered Rows3" = Table.SelectRows(#"Expanded Custom", each ([Kind] = "Sheet")),
#"Filtered Rows4" = Table.SelectRows(#"Filtered Rows3", each Text.Contains([Name], "SLA report")),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows4",{"Name", "Item", "Kind", "Hidden"}),
#"Removed Errors" = Table.RemoveRowsWithErrors(#"Removed Columns", {"Content"}),
#"Invoked Custom Function" = Table.AddColumn(#"Removed Errors", "TestFunction", each FileQuery([Data])),
#"Added Custom1" = Table.AddColumn(#"Invoked Custom Function", "Custom", each Table.IsEmpty([TestFunction])),
#"Filtered Rows6" = Table.SelectRows(#"Added Custom1", each ([Custom] = false)),
#"Expanded TestFunction" = Table.ExpandTableColumn(#"Filtered Rows6", "TestFunction", {"Order ID", "ATM", "City", "Country", "CIT/Vault", "Service", "SLACategory", "Condition", "Serv Acc Mon", "Serv Acc Sat", "Serv Acc Sun", "Status", "Reason", "Description", "Created(CET)", "SLA Target Date(CET)", "Closed(CET)", "Age", "Contractual Reaction Time", "Overdue By absolute", "Overdue By Srv.Hrs", "On Time", "Charged call", "Reference ID", "Reference priority", "Comments", "SLA Category"}, {"Order ID", "ATM", "City", "Country", "CIT/Vault", "Service", "SLACategory", "Condition", "Serv Acc Mon", "Serv Acc Sat", "Serv Acc Sun", "Status", "Reason", "Description", "Created(CET)", "SLA Target Date(CET)", "Closed(CET)", "Age", "Contractual Reaction Time", "Overdue By absolute", "Overdue By Srv.Hrs", "On Time", "Charged call", "Reference ID", "Reference priority", "Comments", "SLA Category"}),
#"Removed Other Columns1" = Table.SelectColumns(#"Expanded TestFunction",{"Order ID", "ATM", "City", "Country", "CIT/Vault", "Service", "Condition", "Reason", "Status", "Description", "Created(CET)", "SLA Target Date(CET)", "Closed(CET)", "Overdue By absolute", "Overdue By Srv.Hrs", "On Time"}),
#"Changed Type" = Table.TransformColumnTypes(#"Removed Other Columns1",{{"Created(CET)", type datetime}, {"SLA Target Date(CET)", type datetime}, {"Closed(CET)", type datetime}}),
#"Added Custom2" = Table.AddColumn(#"Changed Type", "Age", each [#"Closed(CET)"]-[#"Created(CET)"]),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom2",{{"Age", type duration}}),
#"Filtered Rows5" = Table.SelectRows(#"Changed Type1", each [Order ID] <> null and [Order ID] <> "")
in
#"Filtered Rows5"

最佳答案

我认为您表中的标题(您想要扩展的)和您实际扩展的标题存在一些差异。

您已经展开了 SLACategoryOrder ID(在屏幕截图的上半部分),但这些可能应该是 SLA CategoryOrderId 分别(在屏幕截图的下半部分)。请注意间距和大小写的差异。

当您指定要扩展的 header 的 List 时(在下面的 {} 之间):

#"Expanded TestFunction" = Table.ExpandTableColumn(#"Filtered Rows6", "TestFunction", {"Order ID", "ATM", "City", "Country", "CIT/Vault", "Service", "SLACategory", "Condition", "Serv Acc Mon", "Serv Acc Sat", "Serv Acc Sun", "Status", "Reason", "Description", "Created(CET)", "SLA Target Date(CET)", "Closed(CET)", "Age", "Contractual Reaction Time", "Overdue By absolute", "Overdue By Srv.Hrs", "On Time", "Charged call", "Reference ID", "Reference priority", "Comments", "SLA Category"}, {"Order ID", "ATM", "City", "Country", "CIT/Vault", "Service", "SLACategory", "Condition", "Serv Acc Mon", "Serv Acc Sat", "Serv Acc Sun", "Status", "Reason", "Description", "Created(CET)", "SLA Target Date(CET)", "Closed(CET)", "Age", "Contractual Reaction Time", "Overdue By absolute", "Overdue By Srv.Hrs", "On Time", "Charged call", "Reference ID", "Reference priority", "Comments", "SLA Category"}),

我认为你需要要么

  • 完美地硬编码 header 本身(在区分大小写和空格方面)
  • 或动态扩展它们,而不是基于一些硬编码列表。

要动态扩展您的列,您必须执行类似替换此行的操作:

#"Expanded TestFunction" = Table.ExpandTableColumn(#"Filtered Rows6", "TestFunction", {"Order ID", "ATM", "City", "Country", "CIT/Vault", "Service", "SLACategory", "Condition", "Serv Acc Mon", "Serv Acc Sat", "Serv Acc Sun", "Status", "Reason", "Description", "Created(CET)", "SLA Target Date(CET)", "Closed(CET)", "Age", "Contractual Reaction Time", "Overdue By absolute", "Overdue By Srv.Hrs", "On Time", "Charged call", "Reference ID", "Reference priority", "Comments", "SLA Category"}, {"Order ID", "ATM", "City", "Country", "CIT/Vault", "Service", "SLACategory", "Condition", "Serv Acc Mon", "Serv Acc Sat", "Serv Acc Sun", "Status", "Reason", "Description", "Created(CET)", "SLA Target Date(CET)", "Closed(CET)", "Age", "Contractual Reaction Time", "Overdue By absolute", "Overdue By Srv.Hrs", "On Time", "Charged call", "Reference ID", "Reference priority", "Comments", "SLA Category"}),

与:

allHeaders = List.Combine(List.Transform(#"Filtered Rows6"[TestFunction], Table.ColumnNames)),
headersToExpand = List.Distinct(allHeaders),
#"Expanded TestFunction" = Table.ExpandTableColumn(#"Filtered Rows6", "TestFunction", headersToExpand),

(您需要单击查询编辑器左上角的“高级编辑器”并替换那里的代码。)

关于powerquery - 扩展表时 Power Query 缺失值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53956748/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com