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
charleshale
Responsive Resident
Responsive Resident

DAX simple 2 table Intersect .... but via an inactive relationship!

Let's say I have 2 tables both of email address: Table1: Email Subs ("Subs") and Table2: Registered Users ("Registereds").   The intersection between these is straight forward, and I do the following -- which is 2 VARs of distinct columns and the intersection, as below:

 

charleshale_0-1611711484705.png

 

What if, however, the second table is instead a user number and I dont want to lard up the 2nd table with a lookupvalue (that would add a column with the usernumber's email....) and instead want to do that in memory, and the lookupdate of user # and user email is an inactive relationship.   What's the best path?    Var with lookupvalue fails on the indirect.   I suppose I could do a calculatetable and then select columns?     

charleshale_1-1611711847856.png

 

Any advice for what's the most efficient?   Some kind of related function?

 

Thank you

 

Charlie

 

 

 

2 ACCEPTED SOLUTIONS

@charleshale , if both tables have email ids you can use  intersect

 

Var _tab = intersect(all(Table1[email]), All(Table2[email]))

return

calculate(count(Table1[email]), filter(Table1,Table1[email] in _tab))

 

 

But if the tables are joined. then the inner join will give common values

 

in a visual table2[email] and count(Table1[email]) should do

View solution in original post

So, here's the best I have been able to get: merge 2 tables thru a CROSSJOIN and then select the column.   That works.........Not so elegant AND PAINFULLY SLOW but does the job

 

 

~overlap_
VAR _table1 =
    DISTINCT ( Table1[Email] )
VAR _table2 =
   SELECTCOLUMNS(
       CROSSJOIN(Table2,  LookupTable),   //table2 has registered users by # 
       "RegUsersEmail", LookupTable[Email])
        
        
VAR _Intersect =
    INTERSECT ( _table1, _table2 )
RETURN
    COUNTROWS ( DISTINCT ( _Intersect ) )

 

 

View solution in original post

8 REPLIES 8
charleshale
Responsive Resident
Responsive Resident

Hi, @amitchandak, ever present super-user extraordinaire.

Here's a sample file

 

The intersect would be only 1 row  between tables 1 and 2 (Jim@yahoo.com)

charleshale_1-1611715397132.png

 

The question is what's the best way to code an intersect function if I want to use a related table #3 as the lookup instead of the obvious way of simply adding an email address column to table2 via lookupvalue()?   Sorry - important note: assume Table3 is only an inactive relationship so  I might need to use TreatAs or UserRelationship

 

Why I persist in trying to find harder ways to do things is a separate question altogether!

 

 

 

@charleshale , I am not 100% sure, I got what output you want. Please find the attached file after the signature, if that can help

 

Please note that the link you have shared is having other content too. Please hide that if everything is not a public file.

That would work -- nice job -- but how would you do it user intersect ()?  The question I am fundamentally interested in is the intersect between a column in 2 tables when the relationship is indirect.   For example, in the real world, counting the overlap between registered users and email subs when one is an email address and the other expresses itself as a hash that I have to look up through an intermediate table.

So, here's the best I have been able to get: merge 2 tables thru a CROSSJOIN and then select the column.   That works.........Not so elegant AND PAINFULLY SLOW but does the job

 

 

~overlap_
VAR _table1 =
    DISTINCT ( Table1[Email] )
VAR _table2 =
   SELECTCOLUMNS(
       CROSSJOIN(Table2,  LookupTable),   //table2 has registered users by # 
       "RegUsersEmail", LookupTable[Email])
        
        
VAR _Intersect =
    INTERSECT ( _table1, _table2 )
RETURN
    COUNTROWS ( DISTINCT ( _Intersect ) )

 

 

PS a crossfilter would work but that requires a calculate function.     

@charleshale , Yes crossjoin is another good option. Just be careful, it might be costly on bigger data.

@charleshale , if both tables have email ids you can use  intersect

 

Var _tab = intersect(all(Table1[email]), All(Table2[email]))

return

calculate(count(Table1[email]), filter(Table1,Table1[email] in _tab))

 

 

But if the tables are joined. then the inner join will give common values

 

in a visual table2[email] and count(Table1[email]) should do

amitchandak
Super User
Super User

@charleshale , Not very clear. Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

You can create a common email Table 

 

Measure =

var _T1 = distinctcount(Table1[email])

var _T2 = distinctcount(Table2[email])

return

countx(filter(summarize(Table3, Tabl3[email],"_1",_T1, _2,_T2), [T1] >0 && [T2]>0),[email])

 

should give you common between Table1, and Table 2

 

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.