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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
QuangMC
Frequent Visitor

Find the number of unshared values based on filters

Hello everyone,

 

I am currently working on a table that has sales info as such :

Customer IDProduct IDQuantity soldPriceDate sold
1AAA21.50date1
2BBB42.50date2
3CCC13.50date3
2CCC12.50date4
4DDD31date5
3AAA21.50date6

 

What I need to do is get number of different products sold between two clients. For example, if i compare customer 2 and customer 3, it needs to return "1", since there is one product that one client doesn't buy. Much like saying "who buy's what, and who doesn't". It's not a "DISTINCTCOUNT(ProductID);customerID="2"-DISTINCTCOUNT(ProductID);customerID="3"" since i need the different values.

 

It's very similar to a "LEFT OUTER JOIN" in Power Query, followed by a simple count, but the thing is that I only work on one table (there are way too many customers, so I won't be creating one table for each of them). So I'm looking for a mesure (or another way).

 

Is it possible to do something like this "Get the number of DIFFERENT distinct products between two specific customers" ?

I just can't find the right function to work with here.

 

Please feel free to ask more details if i am not clear.

 

Ideas ?

Thanks in advance !

 

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

So something like this? Attached a PBIX as well, Table3, Page3

Measure = 
    VAR __Cust1 = MAX('Customers1'[Customer ID])
    VAR __Cust2 = MAX(Customers2[Customer ID])
    VAR __Table = 
        DISTINCT(
            SELECTCOLUMNS(
                UNION(FILTER('Table3',[Customer ID] = __Cust1),FILTER('Table3',[Customer ID] = __Cust2)),
                "__ProductID",
                [Product ID]
            )
        )
    VAR __Products = DISTINCT('Table3'[Product ID])
RETURN
    CONCATENATEX(EXCEPT(__Products,__Table),[Product ID],",")

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
kentyler
Solution Sage
Solution Sage

You could use COUNTROWS(), if it finds a value then there is at least other product the customer buys.

Do the countrows on the sales table, filtered by the customer and if it returns more that 1 that's your answer.





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


amitchandak
Super User
Super User

You need use except, the input of except can come from summarize, addcolumns along with the filter , customer 1 and 2.

 

If you are only one slicer take max for 1st client and taken min 2nd client.

https://docs.microsoft.com/en-us/dax/except-function-dax

https://docs.microsoft.com/en-us/dax/summarize-function-dax

 

For more than one, some more logic required.

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

 

 

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Greg_Deckler
Super User
Super User

So something like this? Attached a PBIX as well, Table3, Page3

Measure = 
    VAR __Cust1 = MAX('Customers1'[Customer ID])
    VAR __Cust2 = MAX(Customers2[Customer ID])
    VAR __Table = 
        DISTINCT(
            SELECTCOLUMNS(
                UNION(FILTER('Table3',[Customer ID] = __Cust1),FILTER('Table3',[Customer ID] = __Cust2)),
                "__ProductID",
                [Product ID]
            )
        )
    VAR __Products = DISTINCT('Table3'[Product ID])
RETURN
    CONCATENATEX(EXCEPT(__Products,__Table),[Product ID],",")

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hello @Greg_Deckler ,

 

This is very close to what i need indeed ! I can comprehend most of the formula, but would you mind explaining it a bit more what it tells PBI to do ? Like translating the operation so that I am sure that I interpret this the correct way ? 😅

 

Thank you for your quick answer !

 

@amitchandak thank you too for your answer !

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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