我在power-query中加载了一个巨大的excel表(使用import .csv)。此导入会自动检测列类型并分别进行更改:
Table.TransformColumnTypes(#"Höher gestufte Header",{{"ID", Int64.Type}, {"Country", type text}, {"Customer", type text}, {"Release Name", type text}, {"Hardware Systems", type text}, {"Service By", type text}, {"Hwirelease Tags", type text}, {"Country Tags", type text}, {"Created", type datetime}, {"Last Change", type datetime}, {"Scope", type text}, {"PPM PID", Int64.Type}, {"Salesforce IDs", type text}})
问题开始于我知道将源代码更改为与较早的日期不同的.csv,在较早的日期中,之前提到的某些列中不存在nox(例如PPM PID
)。
我收到错误消息,必须手动删除试图更改相应列的命令。
有一些简单的解决方法,以便Power-Query仅在列存在的情况下才尝试更改列类型吗?还是当列名倾向于随时间更改其名称时,我的完整方法不好吗?
答案 0 :(得分:1)
执行此操作的一种方法可能是:
Table.TransformColumnTypes
。举个例子:
let
#"Höher gestufte Header" = Table.FromColumns({
{1, 6, 45, 67},
{"US", "JA", "CA", "GB"}
}, {"ID", "Country"}),
typeTransformations = {{"ID", Int64.Type}, {"Country", type text}, {"Customer", type text}, {"Release Name", type text}, {"Hardware Systems", type text}, {"Service By", type text}, {"Hwirelease Tags", type text}, {"Country Tags", type text}, {"Created", type datetime}, {"Last Change", type datetime}, {"Scope", type text}, {"PPM PID", Int64.Type}, {"Salesforce IDs", type text}},
changeTypes = Table.TransformColumnTypes(#"Höher gestufte Header", List.Select(typeTransformations, each Table.HasColumns(#"Höher gestufte Header", _{0})))
in
changeTypes