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 Help!
Power Apps
Unanswered

SortByColumns Help!

(0) ShareShare
ReportReport
Posted on by 94

I have the below code working fine for filtering my gallery based on a couple comboboxes...

 

 Filter(
EDLS,
And(
Or(
IsBlank(cmb_2_1.SelectedItems.Value),
IsEmpty(cmb_2_1.SelectedItems.Value),
Production_Name in cmb_2_1.SelectedItems.Value
),
Or(
IsBlank(cmb_2_2.SelectedItems.Ep),
IsEmpty(cmb_2_2.SelectedItems.Ep),
Episode_Number in cmb_2_2.SelectedItems.Ep
)
)
)

 

But I now want to add sort buttons.

 

I've added the below code onto 2 buttons...

 

//Button 1

UpdateContext({EpSort: !EpSort})

 

//Button 2

UpdateContext({ProdSort: !ProdSort})

 

I have amended the code on my Gallery to the below but it's not working and I'm a bit stumped...

 

SortByColumns(
Filter(
EDLS,
And(
Or(
IsBlank(cmb_2_1.SelectedItems.Value),
IsEmpty(cmb_2_1.SelectedItems.Value),
Production_Name in cmb_2_1.SelectedItems.Value
),
Or(
IsBlank(cmb_2_2.SelectedItems.Ep),
IsEmpty(cmb_2_2.SelectedItems.Ep),
Episode_Number in cmb_2_2.SelectedItems.Ep
)
),
Episode_Number If(EpSort, Descending, Ascending),
Production_Name If(ProdSort, Descending, Ascending)
)

 

Any help greatly appreciated.

 

Thanks,

Rob

 

Categories:
  • Rajkumar_M Profile Picture
    3,747 Moderator on at

    Hi @RobChilds 

     

    Try this formula,

     

    SortByColumns(
    Filter(
    EDLS,
    And(
    Or(
    IsBlank(cmb_2_1.SelectedItems.Value),
    IsEmpty(cmb_2_1.SelectedItems.Value),
    Production_Name in cmb_2_1.SelectedItems.Value
    ),
    Or(
    IsBlank(cmb_2_2.SelectedItems.Ep),
    IsEmpty(cmb_2_2.SelectedItems.Ep),
    Episode_Number in cmb_2_2.SelectedItems.Ep
    )
    )
    ),
    If(EpSort, "Episode_Number", "Production_Name") & If(EpSort, Descending, Ascending),
    If(ProdSort, "Production_Name", "Episode_Number") & If(ProdSort, Descending, Ascending)
    )

     

    Thanks!

     

    If my response has been helpful in resolving your issue, I kindly request that you consider clicking "Accept as solution" and "giving it a thumbs up" as a token of appreciation.

     

  • RobChilds Profile Picture
    94 on at

    Hi @Rajkumar_404 

     

    Thanks for your reply, but it doesn't immediately work. I still have a blank gallery. 

     

    The red x's have gone, replaced now with a yellow delegation warning triangle.

     

    Also just to mention, my datasource (EDLS) is a Dataverse table in case that makes a difference.

     

    Thanks,

    Rob

  • Rajkumar_M Profile Picture
    3,747 Moderator on at

    Try this formula to avoid delegation warning.

     

    With(
    {
    name: SortByColumns(
    Filter(
    EDLS,
    And(
    Or(
    IsBlank(cmb_2_1.SelectedItems.Value),
    IsEmpty(cmb_2_1.SelectedItems.Value),
    Production_Name in cmb_2_1.SelectedItems.Value
    ),
    Or(
    IsBlank(cmb_2_2.SelectedItems.Ep),
    IsEmpty(cmb_2_2.SelectedItems.Ep),
    Episode_Number in cmb_2_2.SelectedItems.Ep
    )
    )
    ),
    If(EpSort, "Episode_Number", "Production_Name") & If(EpSort, Descending, Ascending),
    If(ProdSort, "Production_Name", "Episode_Number") & If(ProdSort, Descending, Ascending)
    )
    },
    name
    )

     

     

  • timl Profile Picture
    37,424 Super User 2026 Season 2 on at

    Hi @RobChilds 

    In your original formula, there are missing commas between your sort column and sort order values. Is this is a typo in your post here? If not, resolving this may solve your problem.

     

    timl_0-1699009369152.png

     

  • RobChilds Profile Picture
    94 on at

    Hi @Rajkumar_404 

     

    Unfortunately it seems to have made no difference...

     

    Thanks,

    Rob

  • RobChilds Profile Picture
    94 on at

    Hi @timl 

     

    I tried adding in the comma's but it still doesn't work unfortunately.

     

    Thanks,

    Rob

  • Rajkumar_M Profile Picture
    3,747 Moderator on at

    Could you share a screenshot of your code?

  • RobChilds Profile Picture
    94 on at

    @Rajkumar_404 

    Sure thing please see attached. 

     

    I have included my combobox's code as well in case it helps.

    The first combobox (cmb_2_1) uses the distinct function and is sorted alphabetically.

    The second combobox (cmb_2_2) depends upon first combobox.

     

    Many thanks,

    Rob

    Gallery.png
    Combobox-cmb_2_2.png
    Combobox-cmb_2_1.png
  • Rajkumar_M Profile Picture
    3,747 Moderator on at

    Hi @RobChilds 

    Try this 

     

    With(
    {
    name: SortByColumns(
    Filter(
    EDLS,
    And(
    Or(
    IsBlank(cmb_2_1.SelectedItems),
    IsEmpty(cmb_2_1.SelectedItems),
    Production_Name = cmb_2_1.Selected.Value
    ),
    Or(
    IsBlank(cmb_2_2.SelectedItems),
    IsEmpty(cmb_2_2.SelectedItems),
    Episode_Number = cmb_2_2.Selected.Ep
    )
    )
    ),
    "Episode_Number", If(EpSort,SortOrder.Descending, SortOrder.Ascending),
    "Production_Name", If(ProdSort,SortOrder.Descending, SortOrder.Ascending)
    )
    },
    name
    )

    (Or)

     

    With(
    {
    name: SortByColumns(
    Filter(
    EDLS,
    And(
    Or(
    IsBlank(cmb_2_1.SelectedItems),
    IsEmpty(cmb_2_1.SelectedItems),
    Production_Name in cmb_2_1.Selected.Value
    ),
    Or(
    IsBlank(cmb_2_2.SelectedItems),
    IsEmpty(cmb_2_2.SelectedItems),
    Episode_Number in cmb_2_2.Selected.Ep
    )
    )
    ),
    "Episode_Number", If(EpSort,SortOrder.Descending, SortOrder.Ascending),
    "Production_Name", If(ProdSort,SortOrder.Descending, SortOrder.Ascending)
    )
    },
    name
    )

     

  • RobChilds Profile Picture
    94 on at

    @Rajkumar_404 

     

    Neither work unfortunately.

     

    The first batch of code I get red x's. The second is as before, a blank gallery and a yellow warning sign.

     

    Thanks,

    Rob

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

#2
WarrenBelz Profile Picture

WarrenBelz 190 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 135

Last 30 days Overall leaderboard