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 / Add Columns, Sort, and...
Power Apps
Answered

Add Columns, Sort, and Filter

(0) ShareShare
ReportReport
Posted on by 28

Hi friends. 

 

I can get each of these to work individually in the items setting of my gallery, however I am having trouble when trying to nest them. 

 

This works to SORT on the gallery but not filter:

 

 

 

SortByColumns(
 AddColumns(
 ReportDeliveryCustomerGroups,
 "MainCustomerName",
 'Main Customer Name'.Value
 ),
 "MainCustomerName",If(SortDescending2,Descending,Ascending)
)

 

 

 

 

This works to FILTER on the gallery but not sort: 

 

 

 

If(
 IsBlank(CustomerCombobox_2.Selected.Value),
 ReportDeliveryCustomerGroups,
 Filter(
 ReportDeliveryCustomerGroups,
 Customer.Value = CustomerCombobox_2.Selected.Value
 )
)

 

 

 

 

The closest I can come to not getting angry red lines everywhere is this: 

 

 

 

 

SortByColumns(
If(
 IsBlank(CustomerCombobox_2.Selected.Value),
 ReportDeliveryCustomerGroups,
 Filter(
 ReportDeliveryCustomerGroups,
 Customer.Value = CustomerCombobox_2.Selected.Value)
 ),
AddColumns(
 ReportDeliveryCustomerGroups,
 "MainCustomerName",
 'Main Customer Name'.Value
 )
"MainCustomerName"
)

 

 

 

but it's just not working. I've been putting commas and parentheses in different spots and I'm just going in circles. Please help me fix this silly thing. 

 

CDev_83_0-1677003439878.png

Thank you!!

C

 

Categories:
I have the same question (0)
  • Verified answer
    Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @CDev_83 

    Rearranging a bit.

     

    With({_items:AddColumns(
     ReportDeliveryCustomerGroups,
     "MainCustomerName",
     'Main Customer Name'.Value
     )
     },
     SortByColumns(
     Filter(_items, IsBlank(CustomerCombobox_2.Selected.Value)||
     Customer.Value = CustomerCombobox_2.Selected.Value
     ),"MainCustomerName",Ascending
     )
    )
    

     

     

     

  • CDev_83 Profile Picture
    28 on at

    Thank you so much! I don't really ever use the "with" function, I appreciate the help

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @CDev_83 

    I like it because it makes the code so much easier to understand the logic, it doesn't slow down the processing of the code and unlike collections or variables, it only exists during the execution of the code.  I sometimes used to get lost in my own code when I went back to it months later.  I find this really helps. 

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 505

#2
WarrenBelz Profile Picture

WarrenBelz 502 Most Valuable Professional

#3
Haque Profile Picture

Haque 324

Last 30 days Overall leaderboard