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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
geotech
Frequent Visitor

Count number of customers based on grouping/range

Hello All,

 

I have read through similar posts and have attempted to implement the solutions for each, but without success. My version is a bit simplier than the other posts, so it's possible I have been over-applying the solutions. I believe I need to implement Dynamic Segmentation, as discribed here.

 

I have the following table:

Customer Name (or ID)Project Name
Customer 1Project 1
Customer 1Project 2
Customer 2Project 3
Customer 3Project 4
Customer 3Project 5
Customer 3Project 6
Customer 3Project 7
Customer 3Project 8

...continues for the remainder of the data set.

 

I would like to display the number of customers in a bar or pie chart based on the range the project count per customer fall into (1, 2-4, and 5 or more). I have created a Customer Ranges table that looks like this:

Customer Ranges.PNG

The next step I am not sure of - I can create a measure to count the number of projects per customer, I can also create a measure to place the customer into a group (1, 2-4, or 5 or more). Instead, I think I need to create a COUTNROWS function that uses the Customer Ranges table as filter, however I'm not sure how to write this measure.

 

Your help is greatly appreciated, thank you.

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

So, @geotech 

for bar or pie chart use a technique from here https://stackoverflow.com/questions/52169206/dax-grouping-by-a-measure-result

 

Create a dimention table Customer Ranges with one column

Customer Range

1
2 to 4
5 or more

 

next, add a measure to this new table

Measure = 
VAR S = summarize('Table';
'Table'[Customer Name (or ID)];
"CustRange";switch(
true();
countrows('Table')>=5;"5 or more";
countrows('Table')<2;"1";
"2 to 4")
) return
 sumx(S ;if([CustRange]=SELECTEDVALUE('Customer Ranges'[Customer Range]);1;0))

add to a legend field 'Customer Ranges'[Customer Range] and as a Value - this new measure

do not hesitate to give a kudo to useful posts and mark solutions as solution
Linkedin


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

4 REPLIES 4
az38
Community Champion
Community Champion

hi @geotech 

try new measure

Customer Range = switch (
TRUE();
calculate(DISTINCTCOUNT('Table'[Project Name]);ALLEXCEPT('Table';'Table'[Customer Name (or ID)]))=1;"1";
and(calculate(DISTINCTCOUNT('Table'[Project Name]);ALLEXCEPT('Table';'Table'[Customer Name (or ID)])) > 1;calculate(DISTINCTCOUNT('Table'[Project Name]);ALLEXCEPT('Table';'Table'[Customer Name (or ID)])) < 5); "2 to 4"; 
calculate(DISTINCTCOUNT('Table'[Project Name]);ALLEXCEPT('Table';'Table'[Customer Name (or ID)])) >= 5;"5 or more"
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
Linkedin


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
geotech
Frequent Visitor

Thank you, @az38 - that allows me to group each customer by the number of projects per customer:

table.PNG

What I would like to do is plot this data on a bar/pie chart to see the number of customers that fall into each range - is that possible to do using this measure?

az38
Community Champion
Community Champion

So, @geotech 

for bar or pie chart use a technique from here https://stackoverflow.com/questions/52169206/dax-grouping-by-a-measure-result

 

Create a dimention table Customer Ranges with one column

Customer Range

1
2 to 4
5 or more

 

next, add a measure to this new table

Measure = 
VAR S = summarize('Table';
'Table'[Customer Name (or ID)];
"CustRange";switch(
true();
countrows('Table')>=5;"5 or more";
countrows('Table')<2;"1";
"2 to 4")
) return
 sumx(S ;if([CustRange]=SELECTEDVALUE('Customer Ranges'[Customer Range]);1;0))

add to a legend field 'Customer Ranges'[Customer Range] and as a Value - this new measure

do not hesitate to give a kudo to useful posts and mark solutions as solution
Linkedin


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
geotech
Frequent Visitor

@az38, thank you!

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.