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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
bml123
Post Patron
Post Patron

Distinct count by category

Hi,

 

I have a Clients table with client details

Clients IdNameDOBCountry
1  Uk
2  USA
3  UK

 

and another products table 

Product IdProduct TypeClient Id
100P11
101P21
102P12

 

I want to get distinct country count by product type

Product TypeCount of distinct country
P12
P21

 

How do I achieve that?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @bml123 ,

 

Please check this measure.

Measure =
VAR ids =
    CALCULATETABLE (
        VALUES ( products[Client Id] ),
        FILTER (
            ALLSELECTED ( products ),
            products[Product Type] = SELECTEDVALUE ( products[Product Type] )
        )
    )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( Clients[Country] ),
        FILTER ( ALLSELECTED ( Clients ), Clients[Clients Id] IN ids )
    )

vjaywmsft_0-1652773380022.png

 

Best Regards,

Jay

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @bml123 ,

 

Please check this measure.

Measure =
VAR ids =
    CALCULATETABLE (
        VALUES ( products[Client Id] ),
        FILTER (
            ALLSELECTED ( products ),
            products[Product Type] = SELECTEDVALUE ( products[Product Type] )
        )
    )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( Clients[Country] ),
        FILTER ( ALLSELECTED ( Clients ), Clients[Clients Id] IN ids )
    )

vjaywmsft_0-1652773380022.png

 

Best Regards,

Jay

PhilipTreacy
Super User
Super User

Hi @bml123 

 

Download example PBIX file

 

Try this

 

Distinct Country Count by Product Type = CALCULATE(DISTINCTCOUNT([Client Id]), FILTER('Data', 'Data'[Product Type] = SELECTEDVALUE('Data'[Product Type])))

 

 

dc.png

 

regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


jsaunders_zero9
Responsive Resident
Responsive Resident

Hi @bml123 

When you say table do you need this represented in a visual or data table?

Thank you

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.