具有多个过滤器的行数的DAX公式

时间:2018-03-07 19:22:42

标签: excel count powerbi dax

我要求按月找出超过3个“信用卡”帐单的产品数量/数量。表名是“Transactions”

我的数据如下图所示。我怎么能用DAX做到这一点?

Product ID | Billing Type | Year-Month
-----------|--------------|------------
1            Credit Card    2018-01
1            Credit Card    2018-01
1            Online         2018-01
2            Credit Card    2018-01
2            Credit Card    2018-01
1            Credit Card    2018-02
1            Credit Card    2018-02
1            Credit Card    2018-02
1            Credit Card    2018-03
7            Credit Card    2018-03
7            Credit Card    2018-03
4            Credit Card    2018-03
4            Credit Card    2018-03
1            Online         2018-03
1            Online         2018-03
7            Credit Card    2018-04
1            Online         2018-04
5            Online         2018-04

Transactions Table

1 个答案:

答案 0 :(得分:0)

您可以生成一个ProductID值表格以及信用卡交易次数,如下所示:

CalculatedTable =
    SUMMARIZECOLUMNS(
        Transactions[ProductID],
        Transactions[Year-Month],
        "Count",
        COUNTX(FILTER(Transactions, Transactions[BillingType] = "Credit-Card"), 1))

(如果您不想按日期分组,请忽略Transactions[Year-Month]行。)

如果围绕该过滤器包装过滤器,则可以生成仅具有满足过滤器的ProductID值的表。然后只计算该表中的行。

ProductCount = COUNTROWS(FILTER(CalculatedTable, [Count] >= 3))

编辑:听起来我误解了你要问的内容。以下内容将为您提供一个计算表,该表与您在注释中提供的SQL查询相匹配:

CalculatedTable =
    FILTER(
        SUMMARIZECOLUMNS(
            Transactions[Year-Month],
            "RowCount",
            CALCULATE(DISTINCTCOUNT(Transactions[Product ID]), 
                      Transactions[Billing Type] = "Credit Card")),
        [RowCount] >= 10)