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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 358 Most Valuable Professional

#2
11manish Profile Picture

11manish 214 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 185

Last 30 days Overall leaderboard