Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Distinct count active customer by month

Hi,

 

I have a 'transaction table' which have transaction date, amount transacted and account code, which will linked (relationship) to a 'account table' where I can see the client ID and account type for each account.

 

I would like to count the active client ID in each month by account type.

 

I attempted this measuare "Active Client = Calculate(distinctcount('Account'[Client ID]), 'Transaction'[Amount]>0)", then I use a Pivot to tabulate the month in column and account type in row while the measure as value but it is not working.

 

Much appreciate your guidance.

 

Best regards,

 

 

1 ACCEPTED SOLUTION

So, there is a little trick.

 

I created 2 measures:

For Unique Account Code: 

Active Customer:=CALCULATE([Measure];FILTER(Transactions;Transactions[Amount]>0))

 

For Unique Client ID:

Active Customer ID:=CALCULATE(COUNTROWS(VALUES(Customer[Client ID]));FILTER(Transactions;Transactions[Amount]>0))

 

Snip Countrow_Values 3.PNG

 

I hope this is what you are looking for.

 

Best regards.

View solution in original post

16 REPLIES 16
KeithChu
Helper I
Helper I

You need to use RELATED, RELATEDTABLE to get the account-related transaction. In SQL that would be Select  From 'Account' a,'Transaction' t where a.[account code] = t.[account code]. 

 

 

Anonymous
Not applicable

Hi @KeithChu, I am using PowerPivot here and had created a relationship between the account code.

Floriankx
Solution Sage
Solution Sage

Hello, 

 

Why don't you just use COUNTROWS which wraps a VALUES.

Measure:=COUNTROWS(VALUES(Table[Client ID]))

 

Value ensures to count every customer only once no matter how many transactions we causes.

 

If you add you PivotTabe and add Account Type to row content it should do as supposed.

Snip Countrow_Values.PNG

I have Customer Types A and B and Customer IDs from 1 to 4.

You don't have to display Customer ID.

 

Anonymous
Not applicable

Is it possible to show the total of active customers for each month by account type as value instead?

How does an inactive customer appear in your data?

Anonymous
Not applicable

Right now, it show the same number for each month.

If Customers appear with an amount of 0 you can do the following:

 

Active Customer:=CALCULATE([Measure];FILTER(Transactions;Transactions[Amount]>0))

 

You could also wrap the two measures into each other but you should first check if this is working.

Anonymous
Not applicable

@Floriankx, it is showing the same number for each month.

Maybe you can provide some sample data. Here is mine:

Transactions:

Amount         Customer ID Date

0102. Jan
400201. Mrz
153305. Apr
855110. Mrz
445404. Feb
843308. Mrz
648228. Feb
789415. Jan
145109. Apr
843222. Mrz
879418. Jan
349323. Feb
154330. Jan

Class

Custimer ID        Class

1A
2A
3B
4B

I related the table via Customer ID

 

Those are my Measures in the Transaction table:

Measure:=COUNTROWS(VALUES(Transactions[Customer ID]))

Active Customer:=CALCULATE([Measure];FILTER(Transactions;Transactions[Amount]>0))

 

Putting these Measures into a PivotTable Date as Column for Month Values it results in:

Snip Countrow_Values 2.PNG

 

In January for Customer 1 you see the difference. The Amount is 0 so Active Customer is blank but for Measure which counts customer no matter which amount there is 1.

 

Best regards.

Anonymous
Not applicable

My apology and I really appreciate your patience and time for helping me on this.

 

The below is my sample table:

 

Trx DateAccount CodeAmount
1-Mar-18A7119
2-Mar-18A9175
3-Mar-18A3120
4-Mar-18A9107
5-Mar-18A2105
5-Apr-18A4146
6-Apr-18A9169
7-Apr-18A4109
8-Apr-18A6173
9-Apr-18A6179
20-May-18A2153
20-May-18A3195
20-May-18A2131
21-May-18A5175
22-May-18A6146
23-May-18A3185
23-May-18A2191
23-May-18A4179

 

Account CodeAccount TypeClient ID
A1BasicB1
A2PremiumB1
A3BasicB2
A4BasicB2
A5BasicB3
A6BasicB4
A7BasicB5
A8BasicB5
A9PremiumB5
A10PremiumB6

 

 

I had created the relationship using account code.

 

I can get the amount of transaction for each unique Client Code below:

 

Sum of AmountColumn Labels   
 MarAprMayGrand Total
Basic2396078801726
B2120255559934
B3  175175
B4 352146498
B5119  119
Premium3871694751031
B1105 475580
B5282169 451
Grand Total62677613552757

 

 

I would like to achieve the below instead:

Active Client   
 MarAprMayGrand Total
Row Labels   
Basic2234
Premium2112

 

 

So, there is a little trick.

 

I created 2 measures:

For Unique Account Code: 

Active Customer:=CALCULATE([Measure];FILTER(Transactions;Transactions[Amount]>0))

 

For Unique Client ID:

Active Customer ID:=CALCULATE(COUNTROWS(VALUES(Customer[Client ID]));FILTER(Transactions;Transactions[Amount]>0))

 

Snip Countrow_Values 3.PNG

 

I hope this is what you are looking for.

 

Best regards.

Anonymous
Not applicable

@Floriankx, thank you very much. Now the FILTER function better and also learn new function like Countrows. I will look into it further when have time.

 

Reallly appreciate your time and patience for teaching me.

Your Table says 'Sum of Amount'.

Seems like On Board Sum of PivotTable. I think there is also the possibility of 'Count' instead of 'Sum'.

I prefer creating Measure so then you could use my measures as posted before.

 

Best regards.

Phil_Seamark
Employee
Employee

Hi @Anonymous

 

When you say it's not working.  Do you get an error, or incorrect values?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Anonymous
Not applicable

Hi there, incorrect value.

Hello,

 

in first instance there should be a Filter in your calculate:

 "Active Client = Calculate(distinctcount('Account'[Client ID]), Filter(Transaction,'Transaction'[Amount]>0))"

 

I don't know if the formula works then as required, but this might cause the error.

 

Best regards.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.