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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Intersection Problem

CustomerNameProducts
MayankOCEG2
MayankBRT3
LithiaBRT3
LithiaJOG0
LithiaJHOT8
ChrilsHGY7
ShantanuJOG0
JenniferJOG0
JenniferOCEG2
JenniferJHOT8
JenniferBRT3
JenniferHGY7

 

HI, I'm not able to calculate the intersection in Power BI.

Problem- I have Customer name and Product name in one table as two different columns. If i click on customer name  , lets say, mayank and jennifer (multiselect), then number of products should be visible which is common in both. In my example its should be 2 (as product OCEG2 and BRT3 are the product purchased by Mayank and jennifer both.

 

Plus i want to show the common product name also which is common in both.

 

Please help!

Thanks in advance

@Sean 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

for Intersection, i guess this below measure also helpful:

 


IF (
ISBLANK (
CALCULATE(COUNTROWS (
FILTER (
SUMMARIZE (
Cust_table,
Cust_table[CUST_CODE],
"ProductsBought", DISTINCTCOUNT ( Sales[SKU])
),
[ProductsBought] = COUNTROWS ( VALUES ( Sales[SKU] ) )
 
))
))
,
0,
CALCULATE(COUNTROWS (
FILTER (
SUMMARIZE (
Cust_table,
Cust_table[CUST_CODE],
"ProductsBought",DISTINCTCOUNT ( Sales[SKU])
),
[ProductsBought] = COUNTROWS ( VALUES ( Sales[SKU] ) )
)
)))

View solution in original post

10 REPLIES 10
Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

Please try the below DAX expression.

Measure = 
VAR _names = ALLSELECTED( 'Table'[CustomerName] ) 
VAR _products = CALCULATE( COUNT( 'Table'[Products] ), _names ) 
RETURN IF( COUNTROWS( _names ) = _products, 1 )

I've also attached a file with the example in the use.

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
Mariusz Repczynski

 

Anonymous
Not applicable

Hi,

I apologize for my mistake,

But i want to multiselect Product instead of Customer and see how many customer bought both Product (If two products selected in slicer).

 

Thanks!

Hi @Anonymous 

 

Please try the below.

Measure 2 = 
VAR _products = ALLSELECTED( 'Table'[Products] ) 
VAR _names =
ADDCOLUMNS( 
    VALUES( 'Table'[CustomerName] ),
    "xxxx", CALCULATE( COUNTROWS( 'Table' ), _products )
)
RETURN COUNTROWS( FILTER( _names, COUNTROWS( _products ) = [xxxx] ) )

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
Mariusz Repczynski

 

Anonymous
Not applicable

Hi,

@Mariusz 

You Measure is not working in my environment:

ListOfCustomers =
VAR _products = ALLSELECTED( SALESDATA_CASE1[ITEM_CODE])
VAR _names =
ADDCOLUMNS(
VALUES( SALESDATA_CASE1[CustCode_CaseOne] ),
"xxxx", CALCULATE( COUNTROWS( SALESDATA_CASE1 ), _products )
)
RETURN COUNTROWS( FILTER( _names, COUNTROWS( _products ) = [xxxx] ) )
 
I m getting blank values, though actual value isnt blank. I m using Page level filters
Any more information you required to help me on this?
Thanks in Advance!
Anonymous
Not applicable

Hi,

 

This measure is working but it is not giving me what i m looking for.

If i am selecting product 'BRT3' and 'OCEG2' and put Measure2 (what you have created) in values and put Products in column as a matrix Report then it is showing me value of 2 in BRT3 and 2 in OCEG2 and 2 in Total also. The value 2 coming in Total is absolutely correct but BRT3 is bought by 3 customer, similarly OCEG2 is bought by 3 customers and i want to see values as 3 in both product column and 2 in total one.

Currently i m seeing this one:

BRT3OCEG2Total
222

 

What i want is here:

BRT3OCEG2Total
332

 

Thanks!

@Mariusz 

Hi @Anonymous 

 

Please see the below.

Measure 3 = 
MINX( 
    'Table', 
    CALCULATE( 
        COUNTROWS( 'Table' ), 
        ALLSELECTED( 'Table'[CustomerName] ) 
    ) 
)

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
Mariusz Repczynski

 

Anonymous
Not applicable

HI,

@Mariusz 

 

This DAX is working for me. But what if i want to filter out this DAX based on a Measure? (Lets say, i have a measure of average product sold and want to filter my DAX, given by you,based on that measure where average product sold is greater than 10)

Second thing is i'm still not able to get only customers name which bought both products. I'm getting all customer list: please refer below:

Capture.PNG

 

Thanks!

 

Hi @Anonymous 

 

Please see the screenshot and explanation below.

image.png

Red frame matrix represents your previous requirement were you asked to count at the product level and total to including only Customers who bought all selected product, for that please use Measure 3.

 

Green frame table is Using Measure 2 where we are going back to the requirement where you wanted to see how many customers bought all selected products.

 

I'm sure that from the illustration you can see that this requirement are different.

 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
Mariusz Repczynski

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
Mariusz Repczynski

 

Anonymous
Not applicable

HI,

@Mariusz 

My intersection problem is solved. Thank you so much.

But measure 2 is not working for rest of the product combination. Can you please re-check Measure2?

 

Thank you!

Anonymous
Not applicable

for Intersection, i guess this below measure also helpful:

 


IF (
ISBLANK (
CALCULATE(COUNTROWS (
FILTER (
SUMMARIZE (
Cust_table,
Cust_table[CUST_CODE],
"ProductsBought", DISTINCTCOUNT ( Sales[SKU])
),
[ProductsBought] = COUNTROWS ( VALUES ( Sales[SKU] ) )
 
))
))
,
0,
CALCULATE(COUNTROWS (
FILTER (
SUMMARIZE (
Cust_table,
Cust_table[CUST_CODE],
"ProductsBought",DISTINCTCOUNT ( Sales[SKU])
),
[ProductsBought] = COUNTROWS ( VALUES ( Sales[SKU] ) )
)
)))

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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