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
developer-islan
Frequent Visitor

DAX measure to show products that were sold exclusively to the selected customers and no one else

Hi everyone,

I'm working to create a DAX measure [Exclusive Product] to show products that were sold exclusively to the selected customers, and to no one else.

If I filter to show only certain customers within a certain date range, I want to show the products that were sold just to the selected customers.  Products that were also sold to other customers during that time will be excluded.

I've linked to a .pbix with example data and a first attempt (not-yet-working) at the measure below.

Thank you for your help!

 

 

Example_Scenario.png

 

1 ACCEPTED SOLUTION
v-deddai1-msft
Community Support
Community Support

Hi @developer-islan ,

 

You can use the following dax measure:

Exclusive Product1 =
VAR A =
    CALCULATETABLE (
        VALUES ( Sales[Product] ),
        FILTER (
            ALL ( Customers ),
            NOT ( Customers[Customer ID] IN VALUES ( Customers[Customer ID] ) )
        ),
        REMOVEFILTERS ( Products )
    )
VAR B =
    CALCULATETABLE ( VALUES ( Sales[Product] ), REMOVEFILTERS ( Products ) )
RETURN
    IF (
        ISFILTERED ( Customers[Customer ID] ),
        IF ( MAX ( Products[Product] ) IN EXCEPT ( B, A ), 1, 0 ),
        0
    )

 

1.gif

 

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

 

Best Regards,

Dedmon Dai

 

 

View solution in original post

4 REPLIES 4
v-deddai1-msft
Community Support
Community Support

Hi @developer-islan ,

 

You can use the following dax measure:

Exclusive Product1 =
VAR A =
    CALCULATETABLE (
        VALUES ( Sales[Product] ),
        FILTER (
            ALL ( Customers ),
            NOT ( Customers[Customer ID] IN VALUES ( Customers[Customer ID] ) )
        ),
        REMOVEFILTERS ( Products )
    )
VAR B =
    CALCULATETABLE ( VALUES ( Sales[Product] ), REMOVEFILTERS ( Products ) )
RETURN
    IF (
        ISFILTERED ( Customers[Customer ID] ),
        IF ( MAX ( Products[Product] ) IN EXCEPT ( B, A ), 1, 0 ),
        0
    )

 

1.gif

 

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

 

Best Regards,

Dedmon Dai

 

 

amitchandak
Super User
Super User

@developer-islan , Try a meausre like this and put in visual with product id

 

measure =
var _cnt = countrows(allselected(customers[Customer ID]))
return
countx(filter(summarize(Sales, products[product ID], "_1", calculate(distinctCOUNT(customers[Customer ID]), all(sales)), "_2", distinctCOUNT(customers[Customer ID]))
,[_1] =_cnt && [_2] =[_1]),[product ID])

 

in case this did not help

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Hi @amitchandak 

Thank you for your feedback.  This doesn't seem to work as intended.  I've put together the following sample .pbix with the measure and sample data.  Filtering by Customer doesn't show the correct exclusive products.

 

 

Hi,

You may download my PBI file from here.  It is not a perfect solution but good enough to get you started.  In the screenshot below, you can see that P4 was bought only by Customer 1.  When C1 and C2 is selected in the slicer, P3 and P4 are the relevant results because their count in the Measure2 column <= the fisure which appears in the card visual.  I cannot figure out how to filter the figures in the Total column by the figure which appears in the card visual.

Hope this helps.

Untitled.pngUntitled1.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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.