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
JemmaD
Resolver II
Resolver II

Union Distinct multiple columns in Power Query M

Hi there, 

I have four fact tables and I need to create a dimension table pulling two columns from each of the four fact tables.

Let's say the fact tables are named [Table1] [Table2] [Table3] [Table4]

And the two columns I need from each are called [Product] [Branch]

I am able to union distinct on one column, but I can't get the syntax right for two columns.

Here is my code for the one column, can you help me add in the second?

 

 

= Table.Distinct(Table.Combine({
Table.FromColumns ({Table1[Product]}, {"Product"}),
Table.FromColumns ({Table2[Product]}, {"Product"}),
Table.FromColumns ({Table3[PRODUCT]}, {"Product"}),
Table.FromColumns ({Table4[PRODUCT]}, {"Product"})
}))

 

1 ACCEPTED SOLUTION
spinfuzer
Super User
Super User

The problem here is that you have differing column names.  You could make this problem a lot easier by making the column names the same.  A simple Table.Combine would work if all the names were the same.  Because they are not, you can use something like the below.

 

 

= Table.Distinct(Table.FromColumns(
        List.Transform(
            List.Zip({
                Table.ToColumns(Table1[[Product],[Branch]]), 
                Table.ToColumns(Table2[[Product],[Branch]]), 
                Table.ToColumns(Table3[[PRODUCT],[Branch]]),
                Table.ToColumns(Table4[[Product],[BRANCH]])
            }), 
        List.Combine), 
{"Product", "Branch"}))

 

 

 

View solution in original post

2 REPLIES 2
Ahmedx
Super User
Super User

pls try this

 

 

Table.Distinct(
   Table1[[Product],[Branch] ] & 
   Table2[[Product] ,[Branch] ]&
   Table3[[Product] ,[Branch] ]&
   Table4[[Product] ,[Branch] ],
{"Product", "Branch"})

 

 

spinfuzer
Super User
Super User

The problem here is that you have differing column names.  You could make this problem a lot easier by making the column names the same.  A simple Table.Combine would work if all the names were the same.  Because they are not, you can use something like the below.

 

 

= Table.Distinct(Table.FromColumns(
        List.Transform(
            List.Zip({
                Table.ToColumns(Table1[[Product],[Branch]]), 
                Table.ToColumns(Table2[[Product],[Branch]]), 
                Table.ToColumns(Table3[[PRODUCT],[Branch]]),
                Table.ToColumns(Table4[[Product],[BRANCH]])
            }), 
        List.Combine), 
{"Product", "Branch"}))

 

 

 

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.