cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PeanutRhombus
Advocate I
Advocate I

There has to be a cleaner way to do this... Help making this cumbersome?

I have a gallery of a SharePoint list and I'm trying to enable the options to filter it by Location and/or Reason Code and/or Status. Then I want to enable the ability to sort whatever the results may be from the filter by date. Here is what I've done and it works, but it just seems tedious and cumbersome:

 

 

SortByColumns(
    If(
        //All Same
        gallery_Status.Selected.Value = "All" && drop_SiteFilter.Selected.Value = "All" && drop_ReasonFilter.Selected.Value = "All",
        'High Level Inventory Discard'
        ,
        //Different Status
        gallery_Status.Selected.Value <> "All" && drop_SiteFilter.Selected.Value = "All" && drop_ReasonFilter.Selected.Value = "All",
        Filter(
            'High Level Inventory Discard',
            'Discard Status' = gallery_Status.Selected.Value
        ),
        //Different Site
        gallery_Status.Selected.Value = "All" && drop_SiteFilter.Selected.Value <> "All" && drop_ReasonFilter.Selected.Value = "All",
        Filter(
            'High Level Inventory Discard',
            Location.Value = drop_SiteFilter.Selected.Value
        ),
        //Different Reason
        gallery_Status.Selected.Value = "All" && drop_SiteFilter.Selected.Value = "All" && drop_ReasonFilter.Selected.Value <> "All",
        Filter(
            'High Level Inventory Discard',
            'Reason Code'.Value = drop_ReasonFilter.Selected.Value
        ),
        //Different Status and Site
        gallery_Status.Selected.Value <> "All" && drop_SiteFilter.Selected.Value <> "All" && drop_ReasonFilter.Selected.Value = "All",
        Filter(
            'High Level Inventory Discard',
            'Discard Status' = gallery_Status.Selected.Value && Location.Value = drop_SiteFilter.Selected.Value
        ),
        //Different Status and Reason
        gallery_Status.Selected.Value <> "All" && drop_SiteFilter.Selected.Value = "All" && drop_ReasonFilter.Selected.Value <> "All",
        Filter(
            'High Level Inventory Discard',
            'Discard Status' = gallery_Status.Selected.Value && 'Reason Code'.Value = drop_ReasonFilter.Selected.Value
        ),
        //Different Site and Reason
        gallery_Status.Selected.Value = "All" && drop_SiteFilter.Selected.Value <> "All" && drop_ReasonFilter.Selected.Value <> "All",
        Filter(
            'High Level Inventory Discard',
            Location.Value = drop_SiteFilter.Selected.Value && 'Reason Code'.Value = drop_ReasonFilter.Selected.Value
        ),
        //Different All
        gallery_Status.Selected.Value <> "All" && drop_SiteFilter.Selected.Value <> "All" && drop_ReasonFilter.Selected.Value <> "All",
        Filter(
            'High Level Inventory Discard',
            'Discard Status' = gallery_Status.Selected.Value && Location.Value = drop_SiteFilter.Selected.Value && 'Reason Code'.Value = drop_ReasonFilter.Selected.Value
        )
    ),
    "Date",
    If(
        varDateSort = false,
        Ascending,
        Descending
    )
)

 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@PeanutRhombus 

Sure, here you go, same formula but a little easier to work with:

SortByColumns(
    Filter('High Level Inventory Discard'
        (gallery_Status.Selected.Value = "All" || 'Discard Status' = gallery_Status.Selected.Value) && 
        (drop_SiteFilter.Selected.Value = "All" || Location.Value = drop_SiteFilter.Selected.Value) && 
        (drop_ReasonFilter.Selected.Value = "All" || 'Reason Code'.Value = drop_ReasonFilter.Selected.Value)
    ),
    "Date",
    If(varDateSort = false, Ascending, Descending)
)

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

1 REPLY 1
RandyHayes
Super User
Super User

@PeanutRhombus 

Sure, here you go, same formula but a little easier to work with:

SortByColumns(
    Filter('High Level Inventory Discard'
        (gallery_Status.Selected.Value = "All" || 'Discard Status' = gallery_Status.Selected.Value) && 
        (drop_SiteFilter.Selected.Value = "All" || Location.Value = drop_SiteFilter.Selected.Value) && 
        (drop_ReasonFilter.Selected.Value = "All" || 'Reason Code'.Value = drop_ReasonFilter.Selected.Value)
    ),
    "Date",
    If(varDateSort = false, Ascending, Descending)
)

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Top Solution Authors
Top Kudoed Authors
Users online (4,165)