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 using a ...
Power Apps
Unanswered

SortByColumns using a Lookup Column and Filtering

(0) ShareShare
ReportReport
Posted on by 24

I am trying to do the following in the Items for my list (SharePoint list), but it's failing trying to sort by the "Look Up Field" field. Since it's a lookup I know I cannot sort by this column. I have researched and tried using the Add Columns but when I do that it's breaking a different part of my page where I am trying to use my sharepoint look up column and Patch a live change.  What is the easiest way to sort by a look up column. In SharePoint you just click the column, why cannot we just tap into this in Power App for a SharePoint list.

 

SortByColumns
(
    Filter
    (
        [@'API Resource Consumers'],            
        If (
            ShowBlankConsumingProductsCheckbox.Value = true,
                IsBlank('Consuming Product:ID'),
                If(IsBlank(SearchConsumingProductInput.Text), true, SearchConsumingProductInput.Text in 'Consuming Product'.Value))
    ),
    "Look Up Field", SortOrder.Ascending
)
Categories:
I have the same question (0)
  • Verified answer
    Prabhakar_S Profile Picture
    735 Moderator on at

    Hi @JWolmanSymplr ,

     

    Try this,

     

    SortByColumns(
    AddColumns(
    Filter(
    [@'API Resource Consumers'],
    If (
    ShowBlankConsumingProductsCheckbox.Value = true,
    IsBlank('Consuming Product:ID'),
    If(IsBlank(SearchConsumingProductInput.Text), true, SearchConsumingProductInput.Text in 'Consuming Product'.Value)
    )
    ),
    "LookupFieldSort", 'Consuming Product'.LookupField
    ),
    "LookupFieldSort", SortOrder.Ascending
    )

     

    Thanks!!!

     

    Please consider marking my response as the accepted solution if it successfully resolves your concern. If you found the information beneficial in other aspects, kindly express your appreciation by giving it a thumbs-up.

     

  • JWolmanSymplr Profile Picture
    24 on at

    I have tried something similar to this but now my DropDowns in my VerticalGallery are failing in the OnChange method with this error: The specified column 'LookupFieldSort' does not exist. So this solution is breaking other code that works if I don't sort.

    OnChange Method: Patch('API Resource Consumers',ThisItem,{'Consuming Product':ConsumingProductDropdown.SelectedText})
  • Prabhakar_S Profile Picture
    735 Moderator on at

    You can create a separate collection that contains the sorted data and use that collection for your Gallery.

     

    ClearCollect(
    SortedData,
    SortByColumns(
    AddColumns(
    Filter(
    [@'API Resource Consumers'],
    If (
    ShowBlankConsumingProductsCheckbox.Value = true,
    IsBlank('Consuming Product:ID'),
    If(IsBlank(SearchConsumingProductInput.Text), true, SearchConsumingProductInput.Text in 'Consuming Product'.Value)
    )
    ),
    "LookupFieldSort", 'Consuming Product'.LookupField
    ),
    "LookupFieldSort", SortOrder.Ascending
    )
    )

     

    Use SortedData in your Gallery Items Property:

     

    SortedData

     

    In your 'OnChange' method, use 'ThisItem' from the 'SortedData' collection:

     

    Patch('API Resource Consumers', ThisItem, {'Consuming Product': ConsumingProductDropdown.SelectedText})

     

    This way, the 'OnChange' method and the Dropdowns will work with the sorted data and won't conflict with the sorting logic in the Gallery. Adjust the column names and types according to your actual data model.

     

    Thanks!!!

     

    Please consider marking my response as the accepted solution if it successfully resolves your concern. If you found the information beneficial in other aspects, kindly express your appreciation by giving it a thumbs-up.

     

  • JWolmanSymplr Profile Picture
    24 on at

    What method would the ClearCollection go into?

  • JWolmanSymplr Profile Picture
    24 on at

    I was able to fix my OnChange method by doing this:

    Patch('API Resource Consumers',LookUp('API Resource Consumers', ID = ThisItem.ID),{'Publishing Product':PublishingProductDropdown.SelectedText})

    So with your solution and this solution, I feel I am able to continue with what I was doing. 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

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 793 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 333 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard