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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Indo
Regular Visitor

How to Count Unique Customers Based on Only Having Specific Values

Hello,

 

I'm new to Power BI and can't wrap my head around this. I attached a sample table closely related to what I'm trying to figure out.

 

Table1

Customer NameFood Group
AaronFruit
BillFruit

Chris

Meat

Chris

Vegetable

Derek

Vegetable 

Derek

Fruit

Eric

Vegetable

Francine

Meat

Francine

Fruit

Francine

Vegetable

 

How would I count the number of unique customers that only have a food group that is either fruit or vegetable, or both. For example, Aaron, Bill, Derek, Eric would be considered, so 4 total.

 

Also, how would I count the number of unique customers that have a food group that is meat and either fruit or vegetable or both. In this case, only Chris and Francine is considered, in total of 2 customers.

 

Thank you!

1 ACCEPTED SOLUTION

Hi,

Dowload my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

7 REPLIES 7
Indo
Regular Visitor

Hello all,

 

I tried all of your solutions to my real dataset but the second measure for counting a food group that is meat and either fruit or vegetable or both doesn't account for a customer that has 2 or more of each. For example,

 

Table1

Customer NameFood Group
AaronFruit
BillFruit

Chris

Meat

Chris

Vegetable

Derek

Vegetable 

Derek

Fruit

Eric

Vegetable

Francine

Meat

Francine

Fruit

Francine

Vegetable

George

Meat

George

Meat

George

Vegetable

George

Fruit

Heather

Meat

Heather

Meat

Isabel

Fruit

Isabel

Meat

Isabel

Fruit

Isabel

Fruit

Joe

Meat

Joe

Meat

Joe

Vegetable

Kevin

Meat

 

In this updated table, George, Isabel and Joe should be considered in the second measure.

 

Also, since there is a total of 11 unique customers and Heather and Kevin doesn't fit in either measures, (1st measure has Aaron, Bill, Derek, Eric {4 total}), (2nd measure has Chris, Francine, George, Isabel, Joe {5 total}, is it correct to assume that the difference between the total unique customers and sum of both the measures is the total number of customers that only have a food group of meat, which is 2 in this case (Heather, Kevin)?

 

In my real dataset, it is substantially bigger, so the difference isn't clearer to me if I could make that assumption.

 

Thank you!

Hi,

Dowload my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you. This is what I was looking for!

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Jihwan_Kim
Super User
Super User

Hi,

please check the below picture and the attached pbix file.

 

Picture2.png

 

Question one measure: = 
VAR newtable =
    SUMMARIZE (
        FILTER ( Data, Data[Food Group] IN { "Fruit", "Vegetable" } ),
        Data[Customer Name]
    )
VAR othertable =
    SUMMARIZE (
        FILTER ( Data, Data[Food Group] IN { "Meat" } ),
        Data[Customer Name]
    )
VAR resulttable =
    EXCEPT ( newtable, othertable )
RETURN
    CONCATENATEX ( resulttable, Data[Customer Name], ", " ) & " / "
        & COUNTROWS ( resulttable )

 

Question two measure: = 
VAR newtable =
    SUMMARIZE (
        FILTER ( Data, Data[Food Group] IN { "Fruit", "Vegetable" } ),
        Data[Customer Name]
    )
VAR othertable =
    SUMMARIZE (
        FILTER ( Data, Data[Food Group] IN { "Meat" } ),
        Data[Customer Name]
    )
VAR resulttable =
    INTERSECT( newtable, othertable )
RETURN
    CONCATENATEX ( resulttable, Data[Customer Name], ", " ) & " / "
        & COUNTROWS ( resulttable )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
ryan_mayu
Super User
Super User

@Indo 

you can try this

Measure = DISTINCTCOUNT('Table'[Customer Name])- CALCULATE(DISTINCTCOUNT('Table'[Customer Name]),FILTER('Table','Table'[Food Group]="Meat"))
 
Measure 2 =
VAR TBL=DISTINCT(FILTER('Table','Table'[Food Group]="Meat"))
VAR tbl2=ADDCOLUMNS(TBL,"CHECK",CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[Customer Name]=[Customer Name])))
RETURN COUNTROWS(FILTER(tbl2,[CHECK]<>1))
1.PNG




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.