Skip to main content

Notifications

Power Apps - Building Power Apps
Unanswered

SortByColumns Help!

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

 

  • RobChilds Profile Picture
    RobChilds 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

  • Rajkumar_404 Profile Picture
    Rajkumar_404 6 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
    RobChilds 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_404 Profile Picture
    Rajkumar_404 6 on at
    Re: SortByColumns Help!

    Could you share a screenshot of your code?

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

    Hi @timl 

     

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

     

    Thanks,

    Rob

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

    Hi @Rajkumar_404 

     

    Unfortunately it seems to have made no difference...

     

    Thanks,

    Rob

  • timl Profile Picture
    timl 31,980 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

     

  • Rajkumar_404 Profile Picture
    Rajkumar_404 6 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
    )

     

     

  • RobChilds Profile Picture
    RobChilds 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_404 Profile Picture
    Rajkumar_404 6 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.

     

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,487

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,014

Leaderboard