Skip to main content

Notifications

Community site session details

Community site session details

Session Id : 7y4tpSKh+9stBhLBx/WRbv
Power Apps - Building Power Apps
Answered

SortByColumns using a Lookup Column and Filtering

Like (0) ShareShare
ReportReport
Posted on 21 Dec 2023 19:07:13 by 20

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:
  • JWolmanSymplr Profile Picture
    20 on 21 Dec 2023 at 21:27:24
    Re: SortByColumns using a Lookup Column and Filtering

    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!
  • JWolmanSymplr Profile Picture
    20 on 21 Dec 2023 at 20:48:07
    Re: SortByColumns using a Lookup Column and Filtering

    What method would the ClearCollection go into?

  • Prabhakar_S Profile Picture
    735 Super User 2025 Season 1 on 21 Dec 2023 at 19:28:31
    Re: SortByColumns using a Lookup Column and Filtering

    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
    20 on 21 Dec 2023 at 19:20:30
    Re: SortByColumns using a Lookup Column and Filtering

    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})
  • Verified answer
    Prabhakar_S Profile Picture
    735 Super User 2025 Season 1 on 21 Dec 2023 at 19:16:07
    Re: SortByColumns using a Lookup Column and Filtering

    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.

     

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,765 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,091 Most Valuable Professional

Leaderboard