How to combine two Datasources in Power Apps canvas apps?

I am back with another blog in Power Apps and in this blog I shall explain on how to merge Data sources in Power Apps.

Frequently when we work with Canvas apps, we need to merge data sources. Suppose we have two tables.

P.S – When I refer to tables, it’s a datasource and not local table variable inside canvas apps. The formula used here won’t work with local table variables in canvas apps. If you try to use local table inside Patch function mentioned here, you shall get an error – “The first argument of “Patch” should be a collection

Table 1

Table 2

And say we need to combine Table 1 into Table 2. But how to do that?

Well, it can be easily done using the formula below.

ForAll(Table1,
    Patch(Table2,
    Defaults(Table2),
    {
        'First Name': ThisRecord.'First Name',    

'Last Name': ThisRecord.'Last Name',
'Email': ThisRecord.Email


    }
    )
)

In this way you can combine multiple tables into a single table.

Beginners to Power Apps may be wondering what does this formula do? The formula iterates through all the records in Table 1 and then using the Patch function, it add the Table 1 row into Table 2.

Hope this helped!

Debajit Dutta
Business Solutions MVP


Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe to get the latest posts sent to your email.

Discover more from Debajit's Power Apps & Dynamics 365 Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading