web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / SortByColumns dynamic ...
Power Apps
Unanswered

SortByColumns dynamic column delegation

(2) ShareShare
ReportReport
Posted on by 54

Did MS recently change something about the way the SortByColumns function works?

 

Im trying to set the column using a context variable, but when using the variable over a "hard" text value, I get a delegation warning:

 

//In the button
UpdateContext({
 loc_sortByColumn:"Modified",
 loc_sortAscending:!loc_sortAscending
})

//In the gallery -> Delegation warning
SortByColumns(
 productie_vanboxtel_PROCES_DETAIL,
 loc_sortByColumn,
 If(!loc_sortAscending,SortOrder.Descending,SortOrder.Ascending)
)

//In the gallery hardcoded -> No Delegation warning
SortByColumns(
 productie_vanboxtel_PROCES_DETAIL,
 "Modified",
 If(!loc_sortAscending,SortOrder.Descending,SortOrder.Ascending)
)

 

*This has a SharePoint list as a source.

Does anyone know how to fix this? Delegation is important since the datasource is over 2000 rows.

Categories:
I have the same question (0)
  • CU01111442-0 Profile Picture
    54 on at

    Surely there has to be a better solution than doing this for all options right?

    If(
     loc_sortByColumn="Modified",SortByColumns(productie_vanboxtel_PROCES_DETAIL,"Modified",If(!loc_sortAscending,SortOrder.Descending,SortOrder.Ascending)),
     loc_sortByColumn="ID",SortByColumns(productie_vanboxtel_PROCES_DETAIL,"ID",If(!loc_sortAscending,SortOrder.Descending,SortOrder.Ascending))
    )

     

  • sandeepstw Profile Picture
    312 Moderator on at

    Hi @LVerhVRE ,

     

    Here is work around might be helpful -

     

    Update the Button to Set Context Variables

    UpdateContext({ loc_sortByColumn: "Modified", loc_sortAscending: !loc_sortAscending })

    Use the Switch Function in the Gallery Items Property

    SortByColumns(
    productie_vanboxtel_PROCES_DETAIL,
    Switch(
    loc_sortByColumn,
    "Modified", "Modified",
    "ColumnName2", "ColumnName2",
    "ColumnName3", "ColumnName3",
    "DefaultColumn"
    ),
    If(!loc_sortAscending, SortOrder.Descending, SortOrder.Ascending)
    )

     

    Mark as solution if it helps. 

     

    Thanks,

    Sandeep Mishra

  • CU01111442-0 Profile Picture
    54 on at

    LVerhVRE_0-1719307781183.png

    Sadly this still causes the delegation warning.

     

  • Ari00017 Profile Picture
    20 on at
    I am also facing this same issue
  • Suggested answer
    enriqueglopez Profile Picture
    503 Moderator on at
    This has no easy solution. You can't dynamically filter a column without that delegation warning. But, you have some workarrounds:
     
    First. Use With function.

    With(
    {
    listStored: productie_vanboxtel_PROCES_DETAIL //Read note below this code
    },

    SortByColumns(
    listStored,
    loc_sortByColumn,
    If(!loc_sortAscending,SortOrder.Descending,SortOrder.Ascending)
    ))

    Note: listStored will only have 500-2000 (depending on your app config) elements from the online list. This could be an option if your list is not (and wont be) bigger than that.
     
     
    Second. Store all items in a collection.
     
    You can perform this action in the OnStart of your application, with ClearCollect(). Have in mind that you have to filter somehow to batch this, because your filter will only take the first 500-2000 (again, depending on your app config) at once.
     
    Third. Use With but highly filtered.
     
    Let's imagine that you add a mandatory date field in your screen, in order to force users to select a range between dates. You can use that to filter. The objective behind this is to reduce the most the quantity of items that you get from your online database. If you want to get items created by the logged user and between two dates (one year range, for example), that limit of 500-2000 items it's harded to reach.
     
    Example:
    With(
    {
    listStored: Filter(productie_vanboxtel_PROCES_DETAIL, StartDate >= DatePickerStart.SelecteDate And EndDate <= DatePickerEnd.SelectedDate And UserThatCreatedThis = User().Email)
    },

    SortByColumns(
    listStored,
    loc_sortByColumn,
    If(!loc_sortAscending,SortOrder.Descending,SortOrder.Ascending)
    ))


    I hope this helps. Always have in mind that working with delegation means that you have to reduce the items you retrieve by filtering the data as much as you can.

     
  • Suggested answer
    Ari00017 Profile Picture
    20 on at
    Instead of changing the local variable we have to use it in switch directly by 
    Switch(
        comboboxCanvas.Selected.Value,
        "Modified On",
        SortByColumns(
            productie_vanboxtel_PROCES_DETAIL,
            "Modified On",
            SortOrder.Ascending
        ),
        "Created On",
        SortByColumns(
            productie_vanboxtel_PROCES_DETAIL,
            "Created On",
            SortOrder.Ascending
        )
    )
    So, this is a basic approach which will not create delegation issues.
    I faced this problem, but I solved that by this method.
    Hope this Helps If yes then please mark it as Answer.
  • WarrenBelz Profile Picture
    153,032 Most Valuable Professional on at
    Firstly @Ari00017​​​​​​​ is correct, so please mark that solution. Dynamic sort columns are simply not Delegable with SharePoint (there is no short workaround for this).

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard