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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register 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
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.