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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

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
v-jayw-msft
Community Support
Community Support

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

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

3 REPLIES 3
v-jayw-msft
Community Support
Community Support

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

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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