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

Community site session details

Session Id :
Power Apps - Building 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

 

I have the same question (0)
  • Rajkumar_M Profile Picture
    3,722 Super User 2025 Season 2 on at
    Re: SortByColumns Help!

    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
    Re: SortByColumns Help!

    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,722 Super User 2025 Season 2 on at
    Re: SortByColumns Help!

    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
    35,805 Super User 2025 Season 2 on at
    Re: SortByColumns Help!

    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
    Re: SortByColumns Help!

    Hi @Rajkumar_404 

     

    Unfortunately it seems to have made no difference...

     

    Thanks,

    Rob

  • RobChilds Profile Picture
    94 on at
    Re: SortByColumns Help!

    Hi @timl 

     

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

     

    Thanks,

    Rob

  • Rajkumar_M Profile Picture
    3,722 Super User 2025 Season 2 on at
    Re: SortByColumns Help!

    Could you share a screenshot of your code?

  • RobChilds Profile Picture
    94 on at
    Re: SortByColumns Help!

    @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

  • Rajkumar_M Profile Picture
    3,722 Super User 2025 Season 2 on at
    Re: SortByColumns Help!

    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
    Re: SortByColumns Help!

    @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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 663 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 398 Super User 2025 Season 2

#3
developerAJ Profile Picture

developerAJ 235

Last 30 days Overall leaderboard