我正在使用参数从每个客户端文件夹加载文件。某些文件夹不包含 powerquery 加载所需的文件。因为这些文件可能存在也可能不存在。
如果找不到文件,我尝试使用:“尝试 - 否则”将路径更改为“标准文件夹”。
有什么解决办法吗?或者其他方法来解决它? 谢谢!
以下查询将定义两个源,一个是目标,一个是默认源。如果目标没有返回任何文件,那么它将加载默认文件。
let
DefaultSource = Folder.Files("C:\DefaultPath"),
TargetSource = Folder.Files("C:\TargetPath"),
FileCounter = Table.RowCount(Source),
DoSomething = if FileCounter > 0 then TargetSource else DefaultSource
in
DoSomething
如果有效请告诉我
基于@Ricardo Diaz 的回答作为开始(谢谢里卡多!),我成功了:
= let
Path1 = "D:\OneDrive\",
Path2 = "C:\Users\OneDrive\",
DefaultSource = Folder.Files(Path1),
AlternateSource = Folder.Files(Path2),
FileCounter1 = try Table.RowCount(DefaultSource) otherwise 0,
FileCounter2 = try Table.RowCount(AlternateSource) otherwise 0,
WorkingPath = if FileCounter1 > FileCounter2 then Path1 else Path2
in
WorkingPath
希望对你有帮助