power query - 当param为空时由所有人过滤

时间:2016-07-21 15:03:30

标签: dynamic filter powerquery

在Excel,Power Query中,我希望过滤我的数据,以便在参数表中没有提到任何内容(这将带来所有数据)时带来所有数据但是它不起作用...

有什么建议吗?

    project = if param {1} [Value] ="" then  "*" else param {1} [Value],
    "Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Project] = project ))

现在查询有点改变,现在我有3个条件

let

    param = Excel.CurrentWorkbook(){[Name="Secim"]}[Content],

    malzeme = if param {0} [Description] = "" then "*" else param {0} [Description],
    proje = if param {1} [Value] ="" then  "*" else param {1} [Value],
    firma = if param {2} [Value] ="" then  "*" else param {2} [Value],

    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([CODE] = firma ) and ([Project] = proje ) and ([Material Code] = malzeme ))
in
    #"Filtered Rows"

2 个答案:

答案 0 :(得分:2)

您需要更改条件或根本不进行任何过滤。这样的事情应该有效:

"Filtered Rows" = if project = "" then #"Changed Type" else Table.SelectRows(#"Changed Type", each [Project] = project)

答案 1 :(得分:0)

我用下面的查询解决了这个问题:

以:

开头
param = Excel.CurrentWorkbook(){[Name="Secim"]}[Content],


    malzeme = param {0} [Value],
    proje = param {1} [Value],
    firma = param {2} [Value],

并以:

结束
 #"Filtered Rows" = if proje = null then #"Changed Type" else Table.SelectRows(#"Changed Type", each [Project] = proje),
    #"Filtered Rows1" = if malzeme = null then #"Filtered Rows" else Table.SelectRows(#"Filtered Rows", each [Material Code] = malzeme),
    #"Filtered Rows2" = if firma = null then #"Filtered Rows1" else Table.SelectRows(#"Filtered Rows1", each [CODE] = firma)


   in
    #"Filtered Rows2"