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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Distinct count across two tables with multiple critera

Hi!

 

I have two tables, Order Table and Item Table, both of which have the same primary key which is customer ID.

Both tables have a column which are similar but because of the way the database has been designed, they stand alone. Both have the column 'item colour'.

 

I need to a distinct count of the Customer ID's where they have both ordered a blue item colour but I'm struggling to write a measure which will look at both tables and filter both tables on the columns I need.

 

any help would be much appreciated!

1 ACCEPTED SOLUTION
v-weiyan1-msft
Community Support
Community Support

Hi @Anonymous ,

 

Based on your description,, Please try code as below.
My Sample:
Order Table:

vweiyan1msft_0-1704443751800.png

Item Table:

vweiyan1msft_1-1704443773916.png

 

Distinct Blue Customers = 
VAR _OrderTableBlue = CALCULATETABLE(
    VALUES('Order Table'[Customer ID]),
    FILTER(
        'Order Table',
        'Order Table'[Item Colour] = "Blue"
    )
)
VAR _ItemTableBlue = CALCULATETABLE(
    VALUES('Item Table'[Customer ID]),
    FILTER(
        'Item Table',
        'Item Table'[Item Colour] = "Blue"
    )
)
RETURN
COUNTROWS(
    INTERSECT(
        _OrderTableBlue,
        _ItemTableBlue
    )
)

 

 Result is as below.

vweiyan1msft_2-1704443895128.png

If this reply still couldn't help resolve your issue, please provide detailed sample data and the results you are hoping for. We can better understand the problem and help you. Show it as a screenshot or excel. Please remove any sensitive data in advance.

 

Best Regards,
Yulia Yan

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-weiyan1-msft
Community Support
Community Support

Hi @Anonymous ,

 

Based on your description,, Please try code as below.
My Sample:
Order Table:

vweiyan1msft_0-1704443751800.png

Item Table:

vweiyan1msft_1-1704443773916.png

 

Distinct Blue Customers = 
VAR _OrderTableBlue = CALCULATETABLE(
    VALUES('Order Table'[Customer ID]),
    FILTER(
        'Order Table',
        'Order Table'[Item Colour] = "Blue"
    )
)
VAR _ItemTableBlue = CALCULATETABLE(
    VALUES('Item Table'[Customer ID]),
    FILTER(
        'Item Table',
        'Item Table'[Item Colour] = "Blue"
    )
)
RETURN
COUNTROWS(
    INTERSECT(
        _OrderTableBlue,
        _ItemTableBlue
    )
)

 

 Result is as below.

vweiyan1msft_2-1704443895128.png

If this reply still couldn't help resolve your issue, please provide detailed sample data and the results you are hoping for. We can better understand the problem and help you. Show it as a screenshot or excel. Please remove any sensitive data in advance.

 

Best Regards,
Yulia Yan

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.