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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Group Customers by Products Sold

I have a list of 1,000+ customers.  I need to quickly create 4 analytic groupings:

- Group 1: Customers that bought Product A and Not Product B

- Group 2: Customers that bought Product B and Not Product A

- Group 3: Customers that bought both Product A and B

- Group 4: Customers that bought neither Product A or B

 

Should this be done as a measure or a calculated column, and depending on which answer, what is the way to code the DAX or configure the query, respectively?

1 ACCEPTED SOLUTION

Hi @Anonymous,

 

Please refer to below calculated column.

Custom Group =
VAR boughtA =
    IF (
        CALCULATE (
            COUNT ( Sheet1[Product] ),
            FILTER ( ALLEXCEPT ( Sheet1, Sheet1[Customer Number] ), Sheet1[Product] = "A" )
        ) > 0,
        TRUE (),
        FALSE ()
    )
VAR boughtB =
    IF (
        CALCULATE (
            COUNT ( Sheet1[Product] ),
            FILTER ( ALLEXCEPT ( Sheet1, Sheet1[Customer Number] ), Sheet1[Product] = "B" )
        ) > 0,
        TRUE (),
        FALSE ()
    )
RETURN
    IF (
        boughtA = TRUE (),
        IF ( boughtB = TRUE (), "GroupA&B", "GroupA" ),
        IF ( boughtB = TRUE (), "GroupB", "	Group No A or B" )
    )

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
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
LivioLanzo
Solution Sage
Solution Sage

Hi @Anonymous

 

it can be done with a measure, can you pose a sample of your data?

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

Anonymous
Not applicable

Hi @LivioLanzo

 

Here's some excerpt data.  I added the "Custom Group" showing how I want the data grouped.  In Power BI, I can group on Customer Number, however the Customer list is 1,000+ and I'd like to create other customer groupings base on other Product purchase.  Ultimately, the data will be used on a Scatter plot to show Demand curves.

Customer NumberProduct Sales UnitsCustom Group
3100005B       117,7804Group B
3100007B       114,8174Group A&B
3100007C       132,6604Group A&B
3100007A       137,9084Group A&B
3100008B         24,8950Group B
3100011A           2,7140Group A
3100015B         22,3542Group A&B
3100015C         10,3412Group A&B
3100015A           8,9401Group A&B
3100017C           8,0614Group No A or B

Hi @Anonymous,

 

Please refer to below calculated column.

Custom Group =
VAR boughtA =
    IF (
        CALCULATE (
            COUNT ( Sheet1[Product] ),
            FILTER ( ALLEXCEPT ( Sheet1, Sheet1[Customer Number] ), Sheet1[Product] = "A" )
        ) > 0,
        TRUE (),
        FALSE ()
    )
VAR boughtB =
    IF (
        CALCULATE (
            COUNT ( Sheet1[Product] ),
            FILTER ( ALLEXCEPT ( Sheet1, Sheet1[Customer Number] ), Sheet1[Product] = "B" )
        ) > 0,
        TRUE (),
        FALSE ()
    )
RETURN
    IF (
        boughtA = TRUE (),
        IF ( boughtB = TRUE (), "GroupA&B", "GroupA" ),
        IF ( boughtB = TRUE (), "GroupB", "	Group No A or B" )
    )

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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