Power BI(DAX) - 创建度量来计算按条件过滤的不同行

Power BI(DAX)- Create measure to count distinct rows filtered by condition

我有以下 Customer Transactions 数据。在一个月内,客户可以购买一次或多次数据包,也可以不购买数据包。

无论客户在一个月内购买了多少次数据。我正在尝试查找每个客户购买数据的月数。

Total Subscribed Months 是预期列。

因为客户一个月内可能 Data Subscribed (GB) 购买不止一次。首先,我按客户计算一个月内 Total Data Purchased

Total Data Purchased = CALCULATE(
                    SUM('Customer Transactions'[Data Subscribed (GB)]),
                        ALLEXCEPT('Customer Transactions','Customer Transactions'[Account Number],'Customer Transactions'[Date])
    )

其次,计算客户购买数据包的月数。

Total Subscribed Months = 
CALCULATE(
            DISTINCTCOUNT('Customer Transactions'[Account Number] ),
            'Customer Transactions'[Total Data Purchased]>0
            )

但是它不起作用。请告知如何更正公式?

假设您的 table 看起来像这样:

Account Number CUSTOMER_TYPE Data Subscribed(GB) Free Data Date Total Subscribed Months
10001 Retail 250 0 01 October 2019 1
10001 Retail 0 100 01 November 2019 1
10002 Retail 200 0 01 October 2019 1
10002 Retail 250 0 01 November 2019 2
10003 Retail 300 0 01 October 2019 2
10003 Retail 0 0 01 October 2019 2
10003 Retail 100 0 01 October 2019 2
10003 Retail 100 0 01 November 2019 2
10003 Retail 100 0 01 November 2019 2
10003 Retail 0 0 01 December 2019 2

DAX 计算

总订阅月数

Total Subscribed Months = 
CALCULATE (
    DISTINCTCOUNT ( 'Customer Transactions'[Date] ),
    FILTER ( ALL ( 'Customer Transactions'[Data Subscribed(GB)] ), [Data Subscribed(GB)] > 0 )
)

购买的数据总量

Total Data Purchased = 
    SUM('Customer Transactions'[Data Subscribed(GB)])

输出

Table 视觉对象 Account NumberTotal Subscribed MonthsTotal Data Purchased