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
blader1989
Helper II
Helper II

Group customers by counting of their purchase and show in matrix table

Hi guys,

 

I'm now building a DAX that will show us the total count of customer by the number of purchased product with total sales is large than 0 in the matrix table when we filter year & month as my below picture.-

pic.JPG

I have tried all the dax on google but can't find the good solution so I hope you can help me. Here is the link of my files. Thank you in advance!

1 ACCEPTED SOLUTION

@blader1989 
Assuming your sales measure name is [SalesAmount]

DistinctCountOfCustomers = 
Var __productCount = MAX(Query1[NoOfProducts])
Var __Customers = ADDCOLUMNS(Filter(VALUES(raw[Customer Code]), [SalesAmount] >0 ), "ProductCount",  CALCULATE( COUNTROWS(VALUES(raw[Product Name])))) 
var Result = FILTER(__Customers, [ProductCount] = __productCount) 
RETURN COUNTROWS(Result) 

 


If the post helps please give a thumbs up


If it solves your issue, please accept it as the solution to help the other members find it more quickly.


Tharun



View solution in original post

4 REPLIES 4
tharunkumarRTK
Solution Sage
Solution Sage

@blader1989 

I think there are many ways to achieve this result, one approach that I could suggest is:
create a list of numbers from 1 to n (distinct count of products) and created a measure to find number of customers:

DistinctCountOfCustomers = 
Var __productCount = MAX(Query1[NoOfProducts])
Var __Customers = ADDCOLUMNS(VALUES(raw[Customer Code]), "ProductCount",  CALCULATE( COUNTROWS(VALUES(raw[Product Name])))) 
var Result = FILTER(__Customers, [ProductCount] = __productCount) 
RETURN COUNTROWS(Result) 

 

Screenshot 2024-03-25 at 3.46.52 PM.png

If you want you can filter out customers whose total sale value is less than zero.

I am attaching the file here

 


If the post helps please give a thumbs up


If it solves your issue, please accept it as the solution to help the other members find it more quickly.


Tharun

 

Hi @tharunkumarRTK , thank you for your solution. It's look promising so how can I add the condition that the total sales is large than 0 in your formula? In my power BI file, I already have the totalsales DAX.

@blader1989 
Assuming your sales measure name is [SalesAmount]

DistinctCountOfCustomers = 
Var __productCount = MAX(Query1[NoOfProducts])
Var __Customers = ADDCOLUMNS(Filter(VALUES(raw[Customer Code]), [SalesAmount] >0 ), "ProductCount",  CALCULATE( COUNTROWS(VALUES(raw[Product Name])))) 
var Result = FILTER(__Customers, [ProductCount] = __productCount) 
RETURN COUNTROWS(Result) 

 


If the post helps please give a thumbs up


If it solves your issue, please accept it as the solution to help the other members find it more quickly.


Tharun



Hi @tharunkumarRTK , thank you so much. I have added your approach and it's look very good now we are facing new challegening and I hope you can help us that when we click the number of SKUs purchase group on the matrix table, it will only show us which product and customer code in the 2 tables below?

powerbi.JPG

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.