Data - Combine columns from separate tables into a single table

When working with data, there are occasions where it's necessary to combine or merge columns from separate lists, tables, or collections into a single structure. The columns in the source tables would contain the same number of rows and the requirement would be to match on ordinal or row index.

The image beneath illustrates this requirement. Here, there are two separate lists of region codes and region descriptions. The aim is to create a combined collection of codes and descriptions.

Where we often see this requirement is in cases where we retrieve data from web services. There are often times where the return data is split into separate tables. At this point, there will then be the subsequent need to merge the columns into a single structure.

Demonstration - Creating 2 separate collections

To demonstrate this scenario, the formula beneath creates two collections with an identical number of rows. The first collection contains region codes and the second collection includes region descriptions.

ClearCollect( 
colRegionCodes,
{'RegionCode':"E12000002"},
{'RegionCode':"E12000005"},
{'RegionCode':"E12000006"},
{'RegionCode':"S92000003"},
{'RegionCode':"E12000007"},
{'RegionCode':"E12000001"},
{'RegionCode':"N92000002"},
{'RegionCode':"W92000004"},
{'RegionCode':"E12000003"},
{'RegionCode':"E12000004"},
{'RegionCode':"E12000009"},
{'RegionCode':"E12000008"}
)
 
ClearCollect( 
colRegionDescriptions,
{'RegionDesc':"North West"},
{'RegionDesc':"West Midlands"},
{'RegionDesc':"East of England"},
{'RegionDesc':"Scotland"},
{'RegionDesc':"London"},
{'RegionDesc':"North East"},
{'RegionDesc':"Northern Ireland"},
{'RegionDesc':"Wales"},
{'RegionDesc':"Yorkshire and The Humber"},
{'RegionDesc':"East Midlands"},
{'RegionDesc':"South West"},
{'RegionDesc':"South East"}
)

How to merge columns from separate collections into a single table

The formula below shows how to combine the columns from the separate collections into a single table.

ForAll(
Sequence(CountRows(colRegionCodes)),
{
RegionCode:Index(colRegionCodes, Value).RegionCode,
RegionDesc:Index(colRegionDescriptions, Value).RegionDesc
}
)

This formula creates a sequence of numbers based on the number of rows in colRegionCodes. The call to ForAll iterates over this sequence and for each number in the sequence, it retrieves the corresponding row from each collection by calling the Index function. It then retrieves the RegionCode and RegionDesc from the referenced rows.

Here's an illustration of what we see when we set the Items property of a data table control to this formula.


Conclusion

This post demonstrated the formula to merge or combine separate columns from different tables/collections into a single table by creating a numeric sequence and merging by index number.

Related posts

Data - How to remove trailing comma all rows in a table
February 20, 2025
Data - How to find the common rows from 3 or more collections
October 06, 2024
Data - How to show the distinct rows from 2 data sources or collections
February 26, 2024
Data - How to implement circular rotational date sorting
February 21, 2024
Bug - What to do when the data section of the Power Apps Maker portal doesn't work
June 18, 2023
Formula - Transposing/converting rows to columns- an almost impossible task?
September 23, 2021
Data - How to rename field names in a record
July 14, 2021
Data - How to hide duplicate rows in a gallery / show distinct multiple columns in a gallery
July 09, 2021
Data - Retrieving news/forum/blog articles with RSS
June 26, 2021
Data - How to sort by partial numbers in a text field
June 23, 2021
Data - How to return the last record from a table
June 19, 2021
Data - How to create bulk test/dummy records with random values
June 18, 2021
Data - 3 things you should know before using the MySQL or PostgreSQL connectors
May 11, 2021
Data - A walkthrough of how to migrate the data source of an app from Excel to Sharepoint
April 26, 2021
Data - How to enforce unique values (or prevent duplicate values) in one or more columns
April 19, 2021
Data - How much mobile data does Power Apps consume? What ways can we minimise this?
March 28, 2021
Data - How to save and retrieve Google calendar entries
March 14, 2021
Data - How to save and retrieve Google contacts
March 10, 2021
SQL - Caution! This is how users can hack shared SQL connections
January 23, 2021
SharePoint – 2 Mistakes to avoid when importing Excel data
January 10, 2021
SQL - Don't let this DateTime bug catch you out!
January 05, 2021
Settings - What's the purpose of the "Explicit Column Selection" Setting?
January 04, 2021
SQL Server for Beginners Part 3 - Installing On-Premises Gateway
January 24, 2019
SQL Server for Beginners Part 2 - Installing Management Studio
January 14, 2019
SQL Server for Beginners Part 1 - Installing SQL Server
January 04, 2019
Searching data–What you need to know about case sensitivity
December 27, 2018
Images - How to create images that can change depending on data
November 09, 2018
Excel - Reasons NOT to use Excel as a data source
September 25, 2018
SharePoint - What you need to know about Filtering Data
September 16, 2018
Formulas - Generating Row Numbers
April 05, 2018