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 / SortByColumns dynamic ...
Power Apps
Suggested Answer

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
    505 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
    154,411 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

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!

Leaderboard > Power Apps

#1
Haque Profile Picture

Haque 103

#2
WarrenBelz Profile Picture

WarrenBelz 82 Most Valuable Professional

#3
wolenberg_ Profile Picture

wolenberg_ 67 Super User 2026 Season 1

Last 30 days Overall leaderboard