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 with datasource...
Power Apps
Unanswered

Filter with datasource in if construction that evaluates true: different results then without if construction

(0) ShareShare
ReportReport
Posted on by 711

I am trying to let my users choose to search recent data (which is cached in a collection) or all data (the sql datasource itself).

If I do 

ClearCollect(ZoekDieren;SortByColumns(Filter('[dbo].[dier]_1';eZoekTekst.Text in naam);"identificatie_nummer_asiel";Descending))

I get expected results with a certain search string.

But If I do

ClearCollect(ZoekDieren;SortByColumns(Filter(If(!Toggle2.Value;'[dbo].[dier]_1';CachedDieren);eZoekTekst.Text in naam);"identificatie_nummer_asiel";Descending))

with toggle2.value=false (so !toggle2.value=true) I get only results from the first part of the table, so it is doing its delegation thing on me.

 

  • zoekdieren is the collection that is the items propert of my gallery, cacheddieren is collected from the table at app start
  • If I toggle I get different results altogheter so that is not the problem.
  • ; not , is normal in holland

 

How can this be?

Categories:
  • timl Profile Picture
    37,322 Super User 2026 Season 2 on at

    Hi @HansHeintz 

    I would try placing your If function outside of your Filter function. Perhaps that might solve your delegation problem?

     

    ClearCollect(ZoekDieren;
     SortByColumns(
     If(!Toggle2.Value;
     Filter('[dbo].[dier]_1';eZoekTekst.Text in naam);
     Filter(CachedDieren ;eZoekTekst.Text in naam)
     );
     "identificatie_nummer_asiel";
     Descending
     )
    )
  • v-xida-msft Profile Picture
    Microsoft Employee on at

    HI @HansHeintz,

    How many records stored in your SQL Table? More than 2000?

     

    Based on the issue that you mentioned, I think this issue may be related to Delegation issue. When you load data from your '[dbo].[dier]_1' table into the CachedDieren collection, in default, it could only load 500 records from '[dbo].[dier]_1' table into the CachedDieren collection.

    1) If the amount of your  '[dbo].[dier]_1' table records is not more than 2000, please consider set the "Data row limit for Non-delegable queries" option to maximum value -- 2000 within Advanced settings of App settings of your app, then you could load 2000 records at most from '[dbo].[dier]_1' table into the CachedDieren collection, then try your formula again, check if the issue is solved.

     

    2) If the amount of your  '[dbo].[dier]_1' table records is more than 2000, please check and see if the alternative solution mentioned within the following thread would help in your scenario:

    https://powerusers.microsoft.com/t5/General-Discussion/Pulling-in-large-ish-SQL-tables/m-p/243777#M71518

    Set the OnStart property of the App control to following (I assume that there are 10000 records stored in your SQL Table😞

    Concurrent(
     ClearCollect(col1, Filter('[dbo].[dier]_1', recordID >= 1 && recordID <= 2000)),
     ClearCollect(col2, Filter('[dbo].[dier]_1', recordID >= 2001 && recordID <= 4000)),
     ClearCollect(col3, Filter('[dbo].[dier]_1', recordID >= 4001 && recordID <= 6000)),
     ClearCollect(col4, Filter('[dbo].[dier]_1', recordID >= 6001 && recordID <= 8000)),
     ClearCollect(col5, Filter('[dbo].[dier]_1', recordID >= 8001 && recordID <= 10000))
    );
    ClearCollect(CachedDieren, col1, col2, col3, col4, col5)

    Note: I assume that there is a Identity(1,1) column (e.g. recordID column) in your SQL Table to identify the row index.

    then modify your formula as below:

    ClearCollect(
    ZoekDieren;
    SortByColumns(
    Filter(
    If(!Toggle2.Value; '[dbo].[dier]_1'; CachedDieren);
    eZoekTekst.Text in naam
    );
    "identificatie_nummer_asiel";
    Descending
    )
    )

    Or

    ClearCollect(
    ZoekDieren;
    SortByColumns(
    If(
    !Toggle2.Value;
    Filter('[dbo].[dier]_1', eZoekTekst.Text in naam),
    Filter(CachedDieren, eZoekTekst.Text in naam)
    );
    "identificatie_nummer_asiel";
    Descending
    )
    )

    then re-load your app (fire the OnStart proprety of the App control), then check if the issue is solved.

     

    Best regards,

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 342 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 283

#3
Mohsin Ali Profile Picture

Mohsin Ali 221

Last 30 days Overall leaderboard