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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Intersection of 2 Category

I have a transaction table and product category table.
Client buys multiple category product and I need to calculate the count of customer who purchased only type1 and type2 together minus the result of when these category are bought together along with third category

1 ACCEPTED SOLUTION

Hi @Anonymous 

You can refer to the following measure, the sample data is the same as yours

Measure =
VAR a =
    CALCULATETABLE (
        DISTINCT ( 'Table'[Customer_id] ),
        'Table'[Product_category] IN { 1, 2 }
    )
VAR b =
    CALCULATETABLE (
        DISTINCT ( 'Table'[Customer_id] ),
        'Table'[Product_category] = 3
    )
RETURN
    COUNTROWS ( EXCEPT ( a, b ) )

Output

vxinruzhumsft_0-1702367041653.png

Best Regards!

Yolo Zhu

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

3 REPLIES 3
vanessafvg
Super User
Super User

are you able to share some sample data in text format?





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Anonymous
Not applicable

Transaction_idCustomer_idProduct_category
5564023772639911
5564023772639913
5564023772639913
5564023772639911
478109765389742
460966067654781

Hi @Anonymous 

You can refer to the following measure, the sample data is the same as yours

Measure =
VAR a =
    CALCULATETABLE (
        DISTINCT ( 'Table'[Customer_id] ),
        'Table'[Product_category] IN { 1, 2 }
    )
VAR b =
    CALCULATETABLE (
        DISTINCT ( 'Table'[Customer_id] ),
        'Table'[Product_category] = 3
    )
RETURN
    COUNTROWS ( EXCEPT ( a, b ) )

Output

vxinruzhumsft_0-1702367041653.png

Best Regards!

Yolo Zhu

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

 

 

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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.