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

Win a FREE 3 Day Ticket to FabCon Vienna. Apply 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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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