[英]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)![]() |
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 ![]() |
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 visual with Account Number
, Total Subscribed Months
and Total Data Purchased
.带有
Account Number
、 Total Subscribed Months
数和Total Data Purchased
的可视表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.