【问题标题】:Wildcard filter in power query gives 0 output电源查询中的通配符过滤器给出 0 输出
【发布时间】:2022-10-07 18:32:08
【问题描述】:

我的问题是我的previous 问题的扩展。 上一个问题与 powerquery 中的 countifs 和 sumifs 有关,在此有静态搜索,其中搜索 product \"P1\",但 P1 包含更多值。 例如 P1xxxxxx。

以下是我的表格的更新屏幕截图。

以下是在previous 问题中回答的代码

    let Source = Excel.CurrentWorkbook(){[Name=\"Table1\"]}[Content],
#\"Changed Type\" = Table.TransformColumnTypes(Source,{{\"shop\", type text}, {\"shelf\", type text}, {\"product\", type text}}),
#\"Grouped Rows\" = Table.Group(#\"Changed Type\", {\"shop\"}, {
    {\"data\", each Table.AddColumn(_, \"countifs\", each if [product]=\"p1\" then 1 else 0), type table },
    {\"sumifs\", each Table.RowCount(Table.SelectRows(_, each [product] = \"p1\")),type number   }}),
#\"Expanded data\" = Table.ExpandTableColumn(#\"Grouped Rows\", \"data\", {\"shelf\", \"product\", \"countifs\"}, {\"shelf\", \"product\", \"countifs\"})
in #\"Expanded data\"

在上面的代码中 p1 是静态搜索的,但我尝试添加p1表明过滤时它可以在 p1 之前和之后取值。

下面是我尝试过的代码。

let Source = Excel.CurrentWorkbook(){[Name=\"Table1\"]}[Content],
#\"Changed Type\" = Table.TransformColumnTypes(Source,{{\"shop\", type text}, {\"shelf\", type text}, {\"product\", type text}}),
#\"Grouped Rows\" = Table.Group(#\"Changed Type\", {\"shop\"}, {
    {\"data\", each Table.AddColumn(_, \"countifs\", each if [product]=\"*p1*\" then 1 else 0), type table },
    {\"sumifs\", each Table.RowCount(Table.SelectRows(_, each [product] = \"*p1*\")),type number   }}),
#\"Expanded data\" = Table.ExpandTableColumn(#\"Grouped Rows\", \"data\", {\"shelf\", \"product\", \"countifs\"}, {\"shelf\", \"product\", \"countifs\"})
in #\"Expanded data\"

上面的代码输出为 0。

    标签: excel dax powerquery m


    【解决方案1】:

    星号 (*) 不是 M 中的通配符。试试 Text.StartsWith([product], "p1")

    let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"shop", type text}, {"shelf", type text}, {"product", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"shop"}, {
        {"data", each Table.AddColumn(_, "countifs", each if Text.StartsWith([product], "p1") then 1 else 0), type table },
        {"sumifs", each Table.RowCount(Table.SelectRows(_, each Text.StartsWith([product], "p1"))),type number   }}),
    #"Expanded data" = Table.ExpandTableColumn(#"Grouped Rows", "data", {"shelf", "product", "countifs"}, {"shelf", "product", "countifs"})
    in #"Expanded data"
    

    样本数据:

    shop shelf product
    a a1 p123213
    a a2 p212323
    a a3 p113412
    a a4 p14343
    b b1 p251234
    b b2 p2r5324
    b b3 p1e3434
    c c1 p1r43
    c c2 p134
    c c3 p4werwer
    c c4 p32343
    c c5 p1234

    【讨论】:

    • 给出错误:公式防火墙:查询表 1(步骤“添加自定义”)引用其他查询或步骤,因此它可能无法直接访问数据源。请重建此数据组合。
    • 我什至没有在我的代码中使用名为“添加自定义”的步骤,因此该错误不会来自我的代码。上面的代码适用于上面的示例数据。如果您正在调整它,请检查哪些步骤名称输入到其他步骤名称中。您没有提供足够的数据让我们找出那部分
    • @ron 需要配置他的隐私级别,或者重新处理查询。见learn.microsoft.com/en-us/power-bi/enterprise/…support.microsoft.com/en-us/office/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-09
    • 1970-01-01
    • 1970-01-01
    • 2015-04-23
    相关资源
    最近更新 更多