Connecting two lists into one repeat

For this one, i will give an example because i cant explain it otherwise.
we have 2 lists of objects

list1= [
{“id”: “123”,
“age”: “ok”,
“height”: “no”},
{“id”: “456”,
“age”: “go”,
“height”: “take”}]

list2= [
{“id”: “123”,
“age”: “sdf”,
“number”: “lkjh”},
{“id”: “456”,
“age”: “look”,
“number”: “pay”}]

As you can see, the two lists are connected by the ids
The list1 is repeated like

“age”: “ok”,
“height”: “no”

“age”: “go”,
“height”: “take”

And then i need somehow to go and display info from list2 but matching the ids
like:

“age”: “ok”,
“height”: “no”
“number”: “lkjh”

“age”: “go”,
“height”: “take”
“number”: “pay”

And i cant find what formula to use in the extra field (number) in order to display the data like so
I hope you understand my example,
Do you have any idea?

You can use a combination of MAP, FIND_BY_KEY and MERGE

MAP(list1, MERGE[item, FIND_BY_KEY(list2, "id", item.id)])

→ Map over list1, use FIND_BY_KEY to find an item with a matching id in list2, and MERGE it to the item in list1 to create your new merged list :slight_smile:

Hi Mari, thats perfect, i just have some difficulty implementing it,

im setting the page var list

Also i dont know what properties to put in the object in the list

Hi, MERGE uses a list of objects [], not brackets (). If you want to put it in a page var, its properties should be a combination of properties from lists one and two. If you want, you can also do “Repeat with” directly from the formula, so you don’t need a page variable in between.

So helpful,
Youre right, but now it gives me this error

Do you know why?

Its seems like it should be like this, and now im looking for a way to fix that error

Hi, the last parameter of FIND_BY_KEY should be a reference to the current item’s id in MAP:

MAP(list1, MERGE[item, FIND_BY_KEY(list2, "id", item.id)])

1 Like