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 / Trouble with ForAll pa...
Power Apps
Unanswered

Trouble with ForAll patching

(0) ShareShare
ReportReport
Posted on by 53

Hi,

 

I would be grateful for any help on ForAll query as I have spent days looking at this and not getting very far.  

i have three related dataverse tables, Animals, AnimalMedicine, and AnimalMedicineLookup. 

 

the Animal table has a ID, Name and Diseases (multi choice).

 

the AnimalMedicine table has ID, AnimalMedicineLookupID (lookup), Name (lookup), MedicineDescription columns.

 

The AnimalMedicineLookup table has AnimalMedicineLookupID, Diseases (multi choice), MedicineDescription columns.

 

The aim is once a user selects a Name in the Animal gallery, they are taken to a new screen where they can view all the Medicines that are related to the diseases for their selected Animal.  I need to filter the diseases of that Animal from that AnimalMedicineLookup table and then patch it into the AnimalMedicine table so I can use the data in a gallery in a new screen.

 

First of all I have started a collection to collection all diseases of the selected animal.

 

ClearCollect(colDiseases, ThisItem);

 

then obtained the relevant columns

 

ClearCollect(colDiseasesRelevant, ShowColumns, Diseases);

 

then I have filtered the medicines from the MedicineLookup table and then stored in a new collection.

 

ClearCollect(colResults, []);

ForAll(

         colDiseasesRelevant,

        With(

           {matchedRecord: Lookup(colDiseasesRelevant, Diseases = AnimalMedicalLookup.Dieases)},

           If(

               Is Blank(matchedRecord),

               Collect(colResults, 

                    {AnimalMedicineLookupID: ThisRecord}
)

)

)

)

             

Any help would be very, very appreciated.  thank you 🤩 

 

Categories:
I have the same question (0)
  • kelseytran Profile Picture
    292 on at

    Hi @GreenFrog ,

     

    The steps you can do for this are create a collection, extract the relevant columns, filter & collect the matching records, then patch the matching records.  Here's an example of how you can do this:

    Clear(colResults);
    
    ForAll(
     colDiseasesRelevant,
     // Filter AnimalMedicineLookup table for matching diseases
     With(
     {
     matchedRecords: Filter(
     AnimalMedicineLookup,
     ThisRecord.Diseases in AnimalMedicineLookup.Diseases
     )
     },
     Collect(
     colResults,
     ForAll(
     matchedRecords,
     {
     AnimalMedicineLookupID: ThisRecord.AnimalMedicineLookupID,
     Name: ThisRecord.Name, // Assuming Name is a field in AnimalMedicineLookup
     MedicineDescription: ThisRecord.MedicineDescription
     }
     )
     )
     )
    );
    
    ForAll(
     colResults,
     Patch(
     AnimalMedicine,
     Defaults(AnimalMedicine),
     {
     AnimalMedicineLookupID: AnimalMedicineLookupID,
     Name: Name, // Assuming Name is a field in AnimalMedicine
     MedicineDescription: MedicineDescription
     }
     )
    );

    You'll need to change some of the names to accurately reflect your data.

    ------------------------------------------------------------------------------------------------------------------------------
    If I answered your question, please accept my post as a solution and if you liked my response, please give it a thumbs up.

    Thanks!

  • GreenFrog Profile Picture
    53 on at

    Hi,

     

    thank for looking into my problem.  Power Apps does not seem to like the filter in the with statement.  Do you have any other ideas.  Thanks 

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

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 339 Most Valuable Professional

#2
11manish Profile Picture

11manish 180

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 88 Super User 2026 Season 1

Last 30 days Overall leaderboard