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 / Filter data to run faster
Power Apps
Answered

Filter data to run faster

(0) ShareShare
ReportReport
Posted on by 74

Hi!

 

I finally got my Patch expression running but it is SLOOOOOW.

I know, I should swap the Patch and ForAll expressions but, after so many missteps getting to where I am, I'm a bit leery of changing stuff around. 

 

Considering I am specifically and only patching the records of the employees on a previously combobox-selected Organization (therefore, all these employees have the same "OrgId") wouldn't if make it faster if I filter for OrgId before the ForAll or the Patch (whatever works best)? 

 

Please check my working code below and point out how you would change it around to speed it up. Thanks!

---------------------------------------------------------

ForAll(glrEmpleados.AllItems, With(
     {
          _RecEmp: lblRecEmp.Text,
          _OrgId: OrgId,
          _Nombre: inpNombre.Text,
          _Apellidos: inpApellidos.Text,
          _Cargo: inpCargo.Text
     },
     Patch(
     tblEmpleadosAB,
     LookUp(tblEmpleadosAB, RecEmp = _RecEmp),
     {
           // RecEmp:_RecEmp, This line breaks the code and I don't know why


          OrgId: Value(_OrgId),
          Nombre: _Nombre,
          Apellidos: _Apellidos,
          Cargo: _Cargo
     }
     ) // Closes Patch
   ) // Closes With
) // Closes ForAll

---------------------------------------------------------------------

 

Legend:

-   glrEmpleados is the gallery to display and edit the data held in tblEmpleadosAB

-   RecEmp is the Employee identifying field

-   Nombre, Apellidos and Cargo are the column names in the Excel file named EmpleadosAB stored in Sharepoint

-    inpNombre, inpApellidos and inpCargo are the Text Input controls within the Gallery to display and change data

-   I get the organization from a Combobox (cbxOrganizaciones) that user clicks on.

-   I show that value .cbxOrganizaciones.Selected.OrgID  

 

Bonus track: Why does the line RecEmp: _RecEmp, break my snippet? It works Ok without it for edits but I'll try using (almost) the same code for adding records to the table.

 

Thanks for your help!

 

Categories:
  • Scott_Parker Profile Picture
    1,090 on at

    I know you don't want to hear it, but literally the only thing that matters for making it faster is swapping your Patch() and ForAll(). You're just going to have to push through and come out on the other side more confident in using Patch().

     

    You want to use the table arguments for Patch(). Something like:

     

    Patch(
    	tblEmpleadosAB,
    	ForAll(glrEmpleados.AllItems,
    		LookUp(tblEmpleadosAB, RecEmp = lblRecEmp.Text)
    	),
    	ForAll(glrEmpleados.AllItems,
    		{
    			OrgID: Value(OrgId),
    			Nombre: inpNombre.Text,
    			Apellidos: inpApellidos.Text,
    			Cargo: inpCargo.Text
    		}
    	)
    )

     

    You shouldn't/can't change RecEmp because that is your ID column. That would be why your code breaks.

  • MichaelBranches Profile Picture
    74 on at

    Thank you very much (especially for the pep talk!). I know I have to grit my teeth and bear through. I am sooo happy it is finally working. With your suggestions it will be easier (hope!).

    Also, yes, I thought that the breaking was exactly for that reason. I'll just adapt the code when making the new record button.

    Thanks again!

  • MichaelBranches Profile Picture
    74 on at

    Well... Not good.

    I tried the snippet as is and changing it a bit. No luck.

    PA doesn't like the gallery (glrEmpleados). Actually, the whole line has the bold red underline

    It says "Invalid argument type (Table). Expecting a Record value instead."

    Maybe it's a simple tweak to make PA happy?

     

    If not...

    I noticed two important differences:

    1.- You took the "in between" section away:

              {
                     _RecEmp: lblRecEmp.Text,
                     _OrgId: OrgId,
                     _Nombre: inpNombre.Text,
                     _Apellidos: inpApellidos.Text,
                     _Cargo: inpCargo.Text

          },

          This group made a big difference in my previous success. I don't know where to use it (if at all). 

     

    2.- There are 2 ForAll sections. That really threw me. 

         I take it PA makes one table with the record IDs and then it runs through all the fields per record. A little strange for me but, that's why I'm learning.  

    Any hoo... I'm rambling. 

     

    Hope to get some guidance with this faster version.

    Thanks again!

  • Scott_Parker Profile Picture
    1,090 on at

    Assign the results of the ForAll() expressions to variables and see what is in the tables.

     

    The error about expecting a record doesn't make a whole lot of sense to me since Patch() does take table arguments.

     

    Also, I was assuming you were updating existing items only. You would need to make changes if you're also doing new items.

  • MichaelBranches Profile Picture
    74 on at

    Scott, hi

    For the moment I'm only updating existing elements. I'll make a separate button/screen to create records. 

     

    Here is my most recent version:

     

    Patch(
         tblEmpleadosAB,
         ForAll(glrEmpleados.AllItems,
                     LookUp(tblEmpleadosAB, RecEmp = lblRecEmp.Text)
                    ),  // Closes ForAll #1
          ForAll(glrEmpleados.AllItems,
               {
                    OrgID: Value(OrgId),
                    Nombre: inpNombre.Text,
                    Apellidos: inpApellidos.Text,
                    Cargo: inpCargo.Text
               }
         ) // Closes ForAll #2
    ) // Closes Patch

     

    As mentioned before, PA is complaining about the two glrEmpleados gallery calls (the gallery is working perfectly and the call is spelled correctly):

     

    Power Apps 02.png 

    Any thoughts?

    Thanks!

     

     

     

  • Verified answer
    Scott_Parker Profile Picture
    1,090 on at

    Use the As keyword to disambiguate the names.

    Patch(
     tblEmpleadosAB,
     ForAll(glrEmpleados.AllItems As xItem,
     LookUp(tblEmpleadosAB, RecEmp = xItem.lblRecEmp.Text)
     ), // Closes ForAll #1
     ForAll(glrEmpleados.AllItems As xItem,
     {
     OrgID: Value(xItem.OrgId),
     Nombre: xItem.inpNombre.Text,
     Apellidos: xItem.inpApellidos.Text,
     Cargo: xItem.inpCargo.Text
     }
     ) // Closes ForAll #2
    ) // Closes Patch

     

  • MichaelBranches Profile Picture
    74 on at

    Scott,

    PA still doesn't recognize the gallery glrEmpleados and I suspect the reason is the way it is populated (or rather, I can't think of any other reason).

     

    The user can write in three text Inputs called inpBuscaNombre, inpBuscaApellidos and inpBuscaCargo nothing or a substring of the Nombre (FName), Apellidos (LName) and Cargo (Position) of the people they want to show in the gallery. 

     

    There are three items in the gallery made up of those three filtered fields like so:

     

    glrEmpleados items ->

    Filter(
       tblEmpleadosAB,
       OrgId = cbxOrganizaciones.Selected.OrgID,

       Len(inpBuscaNombre.Text)=0 || inpBuscaNombre.Text in Nombre,
       Len(inpBuscaApellidos.Text)=0 || inpBuscaApellidos.Text in Apellidos,

       Len(inpBuscaCargo.Text)=0 || inpBuscaCargo.Text in Cargo

       )

     

    Each filtered line of the gallery line gets its data from tblEmpleados like so:

    inpNombre default -> ThisItem.Nombre

    inpApellidos default -> ThisItem.Apellidos

    inpCargo default -> ThisItem.Cargo

     

    Might this be the reason PA doesn't "get" the gallery, expecting a simple tabular set of data? I really need to filter the data into the gallery so the user can select one row that follows through to another part of the app.

     

    Thanks for your patience!

     

  • Scott_Parker Profile Picture
    1,090 on at

    Could you post the error you're seeing? I cannot see Gallery.AllItems returning anything but a table, so the error has got to be from something else.

  • MichaelBranches Profile Picture
    74 on at

    Yup...

    Power Apps 05B.pngPower Apps 05A.png

  • MichaelBranches Profile Picture
    74 on at

    Agreed...

    I tried a version without the filters and I get the same error. 

    I'll delete the gallery and make a new one

    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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 234 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 207 Most Valuable Professional

#3
timl Profile Picture

timl 122 Super User 2026 Season 2

Last 30 days Overall leaderboard