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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Anonymous
Not applicable

Intersection Issue in DAX

Hi All,

 

Since i didnt get proper solution in last post. I m posting another time.

I have two columns with name Product Code and Customer Name. I want to calculate the unqiue number of customers who bought common Products. For easy going, i m giving sample data here:

ProductCodeCustomerCode
A1001C/001
A1001C/002
B1004C/001
B1004C/004
B1004C/003
C1005C/001

I want following Output:

I drag ProductCode in slicer and select only A1001, then distinct count of customer code should be calculated who bought this Product.

My Output should be 2

Now suppose i multiselect A1001 and B1004 and i should get 1 in output as there is only customer who bought both products.

I also want to see the list of customer who bought both products only or depending upon if i multiselect 3 or 4 Product code.

Basically list of only unique Customers who bought products Based on AND.

 

Any Help would be appreciated

 

Thanks in advance

11 REPLIES 11
Zubair_Muhammad
Community Champion
Community Champion

@Anonymous 

 

Similarly if you want the list of such customers in a card visual, you can use this MEASURE

 

ListOfCustomers =
VAR myproducts =
    COUNTROWS ( ALLSELECTED ( Table1[ProductCode] ) )
RETURN
    CONCATENATEX (
        FILTER (
            VALUES ( Table1[CustomerCode] ),
            COUNTROWS (
                INTERSECT (
                    ALLSELECTED ( Table1[ProductCode] ),
                    CALCULATETABLE ( VALUES ( Table1[ProductCode] ) )
                )
            ) = myproducts
        ),
        [CustomerCode],
        UNICHAR ( 10 )
    )
Anonymous
Not applicable

Hi,

@Zubair_Muhammad 

I want the list of customers in the Grid only as i have more than 10,000 customers.

how do i go for it??

@Anonymous 

 

We can do it with another MEASURE and use it as a VISUAL filter.

 

But is my formula working now?

 

 

 

 

Anonymous
Not applicable

Hi,

@Zubair_Muhammad 

Your Formula for Intersection is still not working in my enviorment, though i have calculated some logics in SQL and import that logic as a column and then used my Previous DAX which i have shared and its working. But i m not able to get the Names of Customers based on my DAX. Can you please help me into this??

@Anonymous 

 

If you can share your file, I will check if I can help

Zubair_Muhammad
Community Champion
Community Champion

@Anonymous 

 

Try this MEASURE

 

Measure =
VAR myproducts =
    COUNTROWS ( ALLSELECTED ( Table1[ProductCode] ) )
RETURN
    COUNTROWS (
        FILTER (
            VALUES ( Table1[CustomerCode] ),
            COUNTROWS (
                INTERSECT (
                    ALLSELECTED ( Table1[ProductCode] ),
                    CALCULATETABLE ( VALUES ( Table1[ProductCode] ) )
                )
            ) = myproducts
        )
    )
Anonymous
Not applicable

HI @Zubair_Muhammad 

 

I' m getting values by selecting individual ProductCode but getting Blank values if i do Multiselect on ProductCode.

Can you suggest for this one?

Hi @Anonymous 

 

I am attaching the pbix file with your sample data

 

I get correct figures as you mentioned.

Please take a look and let me know

Anonymous
Not applicable

Hi,

@Zubair_Muhammad 

Still not working  in my pbix file. 

Momemt i multi-select itemcode, it gives me blank values. However it is working in yours. I m not able to understand .

Please suggest something??

@Anonymous 

 

You can share your file with me if you like.

Are you using some VISUAL or PAGE level filters?

Anonymous
Not applicable

Hi,

@Zubair_Muhammad 

Yes i m using multiple page level filters. Though following DAX is helping in case of Intersection.

But not able to filtered out on DAX Level.

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] ) )
)
)))
 
 
But this gives me result in general, following example will be easy to understand.
I have 3 Items and suppose 100 customers bought each item. It means i have 300 Customers in total (item Wise).
Now by using above DAX i m getting 50 Common Customer who bought all three (if i do multiselect on these 3 items).
But i have a measure of Average quantity also. so if average quantity is greater than 10 then it will included in a list of Customers (what i get in begining is 300, but suppose i will get 250 only while applying this filter) and then only calculate Intersection (AND) dax over this filteres customers.
I m not able to do this.
Suppose:
This is my sample Sales Data:
ItemCustomerQTY
Item1cust14
Item1cust256
Item1cust378
Item2cust33
Item2cust430
Item2cust240
Item2cust567
Item3cust340
Item3cust234

 

What i m getting is count of 2 customers if i do multiselect on Item1 and Item2 and Item3.

But what i want to consider average quantity measure first (that means only consider those customer list where average quantity is greater than 10) which would be:

ItemCustomerQTY
Item1cust256
Item1cust378
Item2cust430
Item2cust240
Item2cust567
Item3cust340
Item3cust234

 

Now if i apply same DAX over here i will get output of 1 customer who bought item1 and Item2 and Item2, which is accurate 

I do not want to apply filter after applying DAX of intersection, rather before doing so i prefer to identify customers based on measure.

 

Please help!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors