Matthew
Matthew

Reputation: 433

PowerBI: Append two tables then identify what rows came from what table originally

I have two tables one with orders from NA and one with orders from EU. I have appended these two tables to have all our orders in one table. Now I want to be able to filter based on the original table. I tried using calculated columns to label the tables but that didn't work with the append. Thanks for your time.

Upvotes: 0

Views: 242

Answers (1)

David Browne - Microsoft
David Browne - Microsoft

Reputation: 89141

I tried using calculated columns to label the tables but that didn't work with the append.

Try again. You just need to add the new column before you append the queries.

In a single Power Query, it would look something like this:

let
    Source1 = Sql.Databases("Server1"),
    DB1 = Source1{[Name="AdventureWorks2017"]}[Data],
    Table1 = DB1{[Schema="Sales",Item="SalesOrderHeader"]}[Data],
    AddedSource1 = Table.AddColumn(Table1, "Source", each "A"),

    Source2 = Sql.Databases("Server2"),
    DB2 = Source2{[Name="AdventureWorks2017"]}[Data],
    Table2 = DB2{[Schema="Sales",Item="SalesOrderHeader"]}[Data],
    AddedSource2 = Table.AddColumn(Table2, "Source", each "B"),

    CombinedTable = Table.Combine({AddedSource1,AddedSource2})

in
    CombinedTable

Upvotes: 1

Related Questions