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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

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
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!

Jan NL Carousel

Fabric Community Update - January 2025

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