web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Merging Collections
Power Apps
Answered

Merging Collections

(0) ShareShare
ReportReport
Posted on by 25

Hello,

 

I am building a timesheet function in powerapps and am trying to build my collection ready for export to Sharepoint List.

 

At the moment i have 2 collections.

 

Collection 1 = EmpCollect

3 columns x "x" rows (max 25)

First Name | Last Name | Employee ID

 

Collection 2 = Booking Record

1 Row x 9 columns

Entry Date | Shift | Type | Booking Code | WO Description | Allowance | Constraints | Hours | Comments

 

I want to merge them into another collection called ShiftRecords which will have the same number of rows as EmpCollect with the information from BookingRecord repeated on each row. It is possible to clear EmpCollect and BookingRecord and continue adding more entries to ShiftRecords. 

 

I have it working but unfortunately have maxed out the add columns function to add the bookingrecords onto empcollect and if i do it the other way round i only get the 1 row. 

 

Any assistance on this would be greatly appreciated 

 

Regards,

 

Patrick Fraser

Categories:
  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    Hi @patrickfraser2 

    If all of your data is contained in one list, then you will have a flawed database.  Unless I am mistaken, you have a One to Many relationship between Employees and Booking records.  They should be separated into two lists.  Unless you have a correct design you will continue to have problems.  Before you go much further, please review my series starting with the overview. https://powerusers.microsoft.com/t5/News-Announcements/Database-Design-Fundamentals-and-PowerApps-An-Overview/ba-p/184485 

  • patrickfraser2 Profile Picture
    25 on at

    Hello @Drrickryp 

     

    None of the information is drawn from within the same list. They are either inputted from within the app or drawn from separate lists in Sharepoint.

     

    I have successfully merged the queries and had no issues with the data. Its just that i run out of availability in my addcolumns function. What i have at the moment is the names being collected on selection and the other data being collected on a button push which also looks to do the merge of the tables. 

     

    I am thinking perhaps i can get the WO info to collect as selected as well so that it removes these steps. 

     

    Patrick

  • patrickfraser2 Profile Picture
    25 on at

    Also i did try adding the data to the collection as a table but it logs it as the table

     

    If this could expand so for the 2 names it creates 2 rows would be exactly what i am after. It puts all the right information into the collection but hides it. There will also be 3 of these columns added  (from EmpCollect)

     
    TableScreenShot.JPG
  • v-siky-msft Profile Picture
    Microsoft Employee on at

    Hi @patrickfraser2 ,

     

    Please try this code, first embed the empcollect collection as the nested table, and then use UnGroup function to expand all.

    ClearCollect(MyCol,UnGroup(AddColumns('Booking Record', "Grouped", EmpCollect),"Grouped"))

     

    Hope this helps.

    Sik

  • patrickfraser2 Profile Picture
    25 on at

    @v-siky-msft 

     

    Thank you for that. I ended up going through it and came up with that solution. 

    Only problem i had was that if i put in the 3 columns i couldnt seem to ungroup them all. So what i did was add the single value as a nested table, ungrouped and then added the columns from the original collection. I did this through 2 temporary collections before it grouped it to the final one

     

    ClearCollect(TempCollect1,{ShiftDate:DatePicker1.SelectedDate,Shift:Radio1.Selected.Value,Type:Radio1_1.Selected.Value,BookingCode:First(ComboBox2.SelectedItems).WorkOrderNumber,WODescription:Label3.Text,Allowances:Dropdown3.SelectedText.Value,Constraints:Dropdown3_1.SelectedText.Value,Hours:TextInput1.Text,Comments:TextInput2.Text,RecordNoBook:"1",EmpID1:EmpCollect.EmpID});ClearCollect(TempCollect2,Ungroup(TempCollect1,"EmpID1"));Collect(ShiftRecords,AddColumns(TempCollect2,"FirstName",LookUp(EmpCollect,EmpID=TempCollect2[@EmpID],FirstName),"LastName",LookUp(EmpCollect,EmpID=TempCollect2[@EmpID],LastName)))

     

    If there is a cleaner way to do it i would be interested in learning it but for now this is working

  • Verified answer
    v-siky-msft Profile Picture
    Microsoft Employee on at

    Hi @patrickfraser2 ,

     

    I have made a test, the 3 columns can be ungrouped well. please see my test.

    1. A Collection with three columns named A1

    2. Try code: ClearCollect(A2,{Test:1,Grouped:A1}); the A1 is nested in the Grouped Column

    3. Try code: ClearCollect(A3, UnGroup(A2,"Grouped")), the nested A1 is expanded.

    Snipaste_2020-04-08_15-44-31.pngSnipaste_2020-04-08_15-44-39.pngSnipaste_2020-04-08_15-44-45.png

    The simpler code:

    ClearCollect(A3,Ungroup(Table({Test:1,Grouped:A1}),"Grouped"))

    In your case:

    ClearCollect(TempCollect1,Ungroup(Table({ShiftDate:DatePicker1.SelectedDate,Shift:Radio1.Selected.Value,Type:Radio1_1.Selected.Value,BookingCode:First(ComboBox2.SelectedItems).WorkOrderNumber,WODescription:Label3.Text,Allowances:Dropdown3.SelectedText.Value,Constraints:Dropdown3_1.SelectedText.Value,Hours:TextInput1.Text,Comments:TextInput2.Text,RecordNoBook:"1",Emp:EmpCollect}),"Emp"))

    Sik

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 243 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 204 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 122

Last 30 days Overall leaderboard