【发布时间】: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