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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
admincaleb007
Frequent Visitor

Joining Tables with multiple columns

I'm wondering if there is a better way to be joining tables based on multiple columns.

 

Basically, I have 2 tables with computer names.  The computer names may be in "Column A" or "Column B" or "Column C" of one table, and then the other table may have computer names in "Column A" or "Column B" or "Column C" of that table.  There may also be cases where a computer name is in Column A+B, or A+B+C, or B+C, etc.

 

What I have been doing is joining (new) based on Table 1.ColA with Table 2.ColA, then joining (new) Table 1.ColB with Table 2.ColA, then joining (new) Table 1.ColC with Table 2.ColA, etc, and continuining until all possibilities are achieved.  This is obviously a huge waste of resources and bandwidth, but I'm not sure how to do some kind of if then column scenario.  I would then append all of the merges into one table which causes a ton of duplicates, but I can visually clean this up by using count(distinct) so that's not a big problem, but something that could just be done a lot better.

 

Any help here?  Can I provide any more information to help?  Exampe tables below.

 

I only started power bi about a week ago so I'm rather new!

 

I have examples of tables below.  I also wouldn't want to match on "nulls", but that's a very small problem.

 

Table1

ColAColBColC
computernamenullnull
nullcomputername2null
nullnullcomputername3
computername4computername4

null

Table2

ColAColBColC
nullcomputernamenull
computername2nullnull
nullcomputername3null
nullcomputername4computername4
1 ACCEPTED SOLUTION
VahidDM
Super User
Super User

Hi @admincaleb007 

 

Try this code to add a new table to your report:

 

Table 3 = 
VAR _A =
    UNION (
        VALUES ( 'Table 1'[ColA] ),
        VALUES ( 'Table 1'[ColB] ),
        VALUES ( 'Table 1'[ColC] )
    )
VAR _AA =
    FILTER ( SUMMARIZE ( _A, [ColA] ), [ColA] <> "null" )
VAR _B =
    UNION (
        VALUES ( 'Table 2'[ColA] ),
        VALUES ( 'Table 2'[ColB] ),
        VALUES ( 'Table 2'[ColC] )
    )
VAR _BB =
    FILTER ( SUMMARIZE ( _B, [ColA] ), [ColA] <> "null" )
RETURN
    SUMMARIZE ( UNION ( _AA, _BB ), [ColA] ) 

 

Output:

 

VahidDM_0-1648423236740.png

 

Download the sample file attached.

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

View solution in original post

1 REPLY 1
VahidDM
Super User
Super User

Hi @admincaleb007 

 

Try this code to add a new table to your report:

 

Table 3 = 
VAR _A =
    UNION (
        VALUES ( 'Table 1'[ColA] ),
        VALUES ( 'Table 1'[ColB] ),
        VALUES ( 'Table 1'[ColC] )
    )
VAR _AA =
    FILTER ( SUMMARIZE ( _A, [ColA] ), [ColA] <> "null" )
VAR _B =
    UNION (
        VALUES ( 'Table 2'[ColA] ),
        VALUES ( 'Table 2'[ColB] ),
        VALUES ( 'Table 2'[ColC] )
    )
VAR _BB =
    FILTER ( SUMMARIZE ( _B, [ColA] ), [ColA] <> "null" )
RETURN
    SUMMARIZE ( UNION ( _AA, _BB ), [ColA] ) 

 

Output:

 

VahidDM_0-1648423236740.png

 

Download the sample file attached.

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.