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 / Lookup between two col...
Power Apps
Answered

Lookup between two collections and update

(0) ShareShare
ReportReport
Posted on by 286

Hello,

         In my PowerApp i have two collections that are brought in from two SharePoint lists at App Run. What i am looking to do is Lookup a particular column value in collection2 and see if it exists in collection1, if it doesn't i want to update collection1 with the record from collection2. 

I've done something similar if the field !IsBlank but not if the record doesn't exist . 

The app is for an employee directory and org chart. The data i am adding is Vacant positions to the main Employee collection. So when it checks the Main Employee collection list and doesn't find a particular position, it pulls that position from my positions collection and adds it to my Employee collection with the Vacant dummy data i have in that collection. 

Does anyone have any suggestions for how i may be able to get this to work?

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @stephenJames 

    Please consider this formula as a solution to your question:

    Collect(collection1, 
     ForAll(
     Filter(collection2, column="columnValue" && !(column in collection2.column)), 
     <either a records structure to match collection1, or ThisRecord if the schema is the same>
     )
    )

    Not sure if you were just interested in one record or all.  The above deals with all of them.  If the schema is the same between collections, then you can specify ThisRecord in the ForAll.  If not, then you will need a record syntax that matches what you want in collection1.

     

    I hope this is helpful for you.

  • stephenJames Profile Picture
    286 on at

    Thanks for the suggestion @RandyHayes 

     

    Here's what i have managed to plug in so far

    Collect(colAll, 
     ForAll(
     Filter(colPositions, JobTitle && !(JobTitle in colPositions.JobTitle)), 
     {
     FirstName: "",
     Last_Name: "",
     FullName: FullName,
     ManagersName: "",
     ManagerJobTitle: ManagerJobTitle,
     WorkPhone: "",
     EMail: Email,
     ol_Departemnt: Department,
     Divsion: Division.Value,
     JobTitle: JobTitle,
     ImageURI: "",
     Locations: Locations,
     Height: "",
     Width: "",
     xCoord: "",
     yCoord: ""
     }
     )
    );

    The structure of colAll is different from colPostions so I'm defining the syntax. However I'm not getting the required results as I think I'm not defining things correctly.
    What i am expecting to happen is any JobTitle in colPostions that isnt found in colAll is collected from colPositions and put into colAll. Because colAll has alot more columns than colPostions i have listed out all the columns in the structure on the left for colAll and blanked out the fields that wont get any data from colPositions. 

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @stephenJames 

    Your filter part of that formula is not correct.

    You are just stating JobTitle as a criteria - this will not evaluate to true or false and nothing will really happen.

    You originally mentioned "Lookup a particular column value in collection2 and see if it exists in collection1"

    So, I assume from the formula you provided that JobTitle is the particular column you want, but you had no value specified - so this is where you need that:

    Filter(colPositions, JobTitle="some Title" && !(JobTitle in colPositions.JobTitle)), 

    And actually, I notice a slight mistake in my formula, you also want to see if this exists in collection1, so the filter formula should be:

    Filter(colPositions, JobTitle="some Title" && !(JobTitle in colAll.JobTitle)), 

     

  • stephenJames Profile Picture
    286 on at

    @RandyHayes 

    So if i have multiple jobtitles i needs to check against would i need to duplicate the code multiple times 

    for example 

    Filter(colPositions, JobTitle="Jobtitle1" && !(JobTitle in colAll.JobTitle)),
    Filter(colPositions, JobTitle="Jobtitle2" && !(JobTitle in colAll.JobTitle)),
    Filter(colPositions, JobTitle="Jobtitle3" && !(JobTitle in colAll.JobTitle)),

    Or is there a way to bunch it all up together to grab all the jobtitles from one collection and check if they exist in the other and add them if they don't.

    I apologize if my original comment didn't explain what i am trying to achieve clearly.

  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @stephenJames 

    No, that would not work, you would need this:

    Filter(colPositions, JobTitle in "Jobtitle1|Jobtitle2|Jobtitle3" && !(JobTitle in colAll.JobTitle)),

    This will give you what you need.

     

     

  • stephenJames Profile Picture
    286 on at

    Thanks @RandyHayes that was exactly what i was looking for.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 610

#2
Haque Profile Picture

Haque 317

#3
WarrenBelz Profile Picture

WarrenBelz 315 Most Valuable Professional

Last 30 days Overall leaderboard