简体   繁体   English

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

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

I have below Customer Transactions data.我有以下Customer Transactions数据。 In a month, customer may buy one or multiple times data pack,or may not buy data pack.在一个月内,客户可以购买一次或多次数据包,也可以不购买数据包。

Irrespective of how many times data purchased in a month by a customer.无论客户在一个月内购买了多少次数据。 I'm trying to find number of months that each customer purchased the data.我正在尝试查找每个客户购买数据的月数。 在此处输入图像描述

Total Subscribed Months is expected column. Total Subscribed Months是预期列。

Since customer may buy Data Subscribed (GB) more than once in a month.由于客户可能在一个月内多次购买Data Subscribed (GB) First I'm calculating Total Data Purchased in a month by customer.首先,我计算客户在一个月内Total Data Purchased

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

Second, Calculate number of months customer purchased the data pack.其次,计算客户购买数据包的月数。

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

But its not working.但它不起作用。 Please advise how to correct formulae?请指教如何修正公式?

Assuming your table looks like this:假设您的表如下所示:

Account Number账号 CUSTOMER_TYPE顾客类型 Data Subscribed(GB)订阅数据(GB) Free Data免费数据 Date日期 Total Subscribed Months总订阅月数
10001 10001 Retail零售 250 250 0 0 01 October 2019 2019 年 10 月 1 日 1 1个
10001 10001 Retail零售 0 0 100 100 01 November 2019 2019 年 11 月 1 日 1 1个
10002 10002 Retail零售 200 200 0 0 01 October 2019 2019 年 10 月 1 日 1 1个
10002 10002 Retail零售 250 250 0 0 01 November 2019 2019 年 11 月 1 日 2 2个
10003 10003 Retail零售 300 300 0 0 01 October 2019 2019 年 10 月 1 日 2 2个
10003 10003 Retail零售 0 0 0 0 01 October 2019 2019 年 10 月 1 日 2 2个
10003 10003 Retail零售 100 100 0 0 01 October 2019 2019 年 10 月 1 日 2 2个
10003 10003 Retail零售 100 100 0 0 01 November 2019 2019 年 11 月 1 日 2 2个
10003 10003 Retail零售 100 100 0 0 01 November 2019 2019 年 11 月 1 日 2 2个
10003 10003 Retail零售 0 0 0 0 01 December 2019 2019 年 12 月 1 日 2 2个

DAX Calculations DAX 计算

Total Subscribed Months总订阅月数

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

Total Data Purchased购买的数据总量

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

Output Output

Table visual with Account Number , Total Subscribed Months and Total Data Purchased .带有Account NumberTotal Subscribed Months数和Total Data Purchased的可视表。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM