Forum Discussion

JemmaD's avatar
JemmaD
Icon for Helper V rankHelper V
3 years ago
Solved

Union two columns from two tables together in Power Query

Hi there,

I have two tables : Policies and Quotes. In both tables is a column called [Product]

I want to create a dimension table holding distinct values of [Product] from both Policies and Quotes tables. 

I want to do this in m query, not Dax.

Please help with the syntax! 

  • Solved! Just stick a Table.Distinct in front of the Table.Combine query and add an additional close parameter at the end of the query:

    = Table.Distinct(Table.Combine({Table.FromColumns({Policies[Product]}, {"Product"}), Table.FromColumns ({Quotes[Product]}, {"Product"})}))



4 Replies

  • ITManuel's avatar
    ITManuel
    Icon for Responsive Resident rankResponsive Resident

    Hi JemmaD ,

     

    you can do this pretty easily via the graphical interface in Power Query.

    1. Append the two tables as new tables

    2. Remove all columns except [Product]

    3. Remove duplicates from the column [Product]

     

    This would be the M code

     

    let
        Source = Table.Combine({Policies, Quotes}),
        #"Removed Other Columns" = Table.SelectColumns(Source,{"Product"}),
        #"Removed Duplicates" = Table.Distinct(#"Removed Other Columns")
    in
        #"Removed Duplicates"
    • JemmaD's avatar
      JemmaD
      Icon for Helper V rankHelper V

      Apparently there is a way to select the Product column within the Table.Combine argument, I just can't get the syntax right. 

  • I got this:

    = Table.Combine({Table.FromColumns({Policies[Product]}, {"Product"}), Table.FromColumns ({Quotes[Product]}, {"Product"})})
    But it doesn't create a distinct list

    • JemmaD's avatar
      JemmaD
      Icon for Helper V rankHelper V

      Solved! Just stick a Table.Distinct in front of the Table.Combine query and add an additional close parameter at the end of the query:

      = Table.Distinct(Table.Combine({Table.FromColumns({Policies[Product]}, {"Product"}), Table.FromColumns ({Quotes[Product]}, {"Product"})}))