【问题标题】:Power query & power pivot - empty table and clearing pivot电源查询和电源支点 - 空表和清除支点
【发布时间】:2016-06-02 17:15:26
【问题描述】:

希望您能提供帮助。 我的电源查询中有以下代码,它与连接的电源数据透视表配合得很好。 一旦 Source 行返回“This table is empty”,一切都会出错:

  1. 电源查询返回错误消息,即源行后面的 2 行无法识别。
  2. power Pivot 中的表显示了上一个工作查询的最后结果。

如果没有结果,我需要表格为空。

我该怎么做?

let

    UrlSource = Excel.CurrentWorkbook(){[Name="Table6"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(UrlSource,{{"Url", type text}}),
    Url = #"Changed Type"{0}[Url],

    UserInput = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Sagsnummer Type" = Table.TransformColumnTypes(UserInput,{{"Sagsnummer", type text}}),
    Sagsnummer = #"Changed Sagsnummer Type"{0}[Sagsnummer],

    Source = OData.Feed(Url & "/FileContacts?$select=CustomLabel_Summary,Name/Name1&$expand=Name&$filter=File/FileNo eq '" & Sagsnummer & "'"),
    #"Expanded Name" = Table.ExpandRecordColumn(Source, "Name", {"Name1"}, {"Name.Name1"}),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded Name",{{"CustomLabel_Summary", "Rolle"}, {"Name.Name1", "Kontakt"}})

in

    #"Renamed Columns"

【问题讨论】:

    标签: excel powerpivot powerquery


    【解决方案1】:

    添加最后一步,检查 UrlSource 和 UserInput 是否有一行输入。如果没有,默认为一些空表:

    = if Table.RowCount(UrlSource) > 0 and Table.RowCount(UserInput) > 0 then #"Renamed Columns" else #table({"Rolle", "Kontakt"}, {})
    

    所有这些,你的代码看起来像

    let
    
        UrlSource = Excel.CurrentWorkbook(){[Name="Table6"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(UrlSource,{{"Url", type text}}),
        Url = #"Changed Type"{0}[Url],
    
        UserInput = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        #"Changed Sagsnummer Type" = Table.TransformColumnTypes(UserInput,{{"Sagsnummer", type text}}),
        Sagsnummer = #"Changed Sagsnummer Type"{0}[Sagsnummer],
    
        Source = OData.Feed(Url & "/FileContacts?$select=CustomLabel_Summary,Name/Name1&$expand=Name&$filter=File/FileNo eq '" & Sagsnummer & "'"),
        #"Expanded Name" = Table.ExpandRecordColumn(Source, "Name", {"Name1"}, {"Name.Name1"}),
        #"Renamed Columns" = Table.RenameColumns(#"Expanded Name",{{"CustomLabel_Summary", "Rolle"}, {"Name.Name1", "Kontakt"}}),
    
        Custom1 = if Table.RowCount(UrlSource) > 0 and Table.RowCount(UserInput) > 0 then #"Renamed Columns" else #table({"Rolle", "Kontakt"}, {})
    in
    
        Custom1
    

    【讨论】:

    • Carl Tnx 的答案。我不太明白..你能把它放在我的代码中吗? tnx
    • 当然可以。公式栏有一个添加自定义公式的按钮,可以在底部添加一个步骤:)
    • Tnx Carl...欣赏它:-)
    猜你喜欢
    • 2015-08-31
    • 2013-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多