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 / Complicated filter help
Power Apps
Unanswered

Complicated filter help

(0) ShareShare
ReportReport
Posted on by 421

Hi everyone.  I have a complicated filter on a gallery in my asset management app.  I am trying to give the user the option to sort by either NBV or TitleName, but its currently sorting by NBV correctly BUT when I try and sort by TitleName, its only sorting part of the list that has a NBV.  I received help writing this code, the portion I have added is the varnamesort and "_calcabc",
Text(TitleGame).

 

Any help would be greatly appreciated!

 

Chris

 

 

Filter(
DropColumns(
SortByColumns(
AddColumns(
Search(
Filter(
AmusementAssets,
TextBarcode = varBarcodeScanSSC,
(Checkbox15_1.Value = true || GameAssetStatus <> "On Floor"),
(Dropdown8_5.Selected.Name = "All") || GameAssetStatus = Dropdown8_5.Selected.Name,
CurrentStoreName = Switch(
varUser.Department,
"6250",
"Franklin-0038",
varUser.OfficeLocation
)
),
tiGameName_6.Text,
"cr3db_name",
"cr3db_textbarcode",
"cr3db_serialnumber"
),
"_calced",
Value('NBV-eliminate Negative'),
"_calcabc",
Text(TitleGame)

),
"_calced",
If(
varNBVSort,
Descending,Ascending
), "_calcabc",If(
varNameSort,
Descending,Ascending
)
),
"_calced",
"_calcabc"
),
Slider4_11.Value = 0 || SetForRetirement = Switch(
Slider4_11.Value,
1,
"Yes",
2,
Blank()
),
Slider4_10.Value = 2 || Archived = Switch(
Slider4_10.Value,
1,
"Yes",
0,
Blank()
)
)

Categories:
  • WarrenBelz Profile Picture
    156,748 Most Valuable Professional on at

    Hi @ckserra33 ,

    Your current Sort is this

    "_calced",
    If(
     varNBVSort,
     Descending,
     Ascending
    ), 
    "_calcabc",
    If(
     varNameSort,
     Descending,
     Ascending
    )

    which means it sorts by _calced and then by _calcabr

     

    If you want to sort by one or the other (forgetting about the sort order) - and use Sort() at the top, not SortByColumns)

    If(
     varNBVSort,
     _calced,
     varNameSort
     _calcabc
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • ckserra33 Profile Picture
    421 on at

    @WarrenBelz Hi Warren, thank you for the response.  I have made the changes above but get an error on the If statement that is added. Here is the filtered code and error:

    ckserra33_0-1669762460055.png

     

     

     

     

    Here is the full updated code

    Filter(
    DropColumns(
    Sort(
    AddColumns(
    Search(
    Filter(
    AmusementAssets,
    (Dropdown8_5.Selected.Name = "All") || GameAssetStatus = Dropdown8_5.Selected.Name,
    CurrentStoreName = Switch(
    varUser.Department,
    "6250",
    "Depot",
    varUser.OfficeLocation
    ),
    (Checkbox15_1.Value = false || GameAssetStatus <> "On Floor")
    ),
    tiGameName_6.Text,
    "cr3db_name",
    "cr3db_textbarcode",
    "cr3db_serialnumber"
    ),
    "_calced",
    Value('NBV-eliminate Negative'),
    "_calcabc",
    TitleGame
    ),If(
    varNBVSort,
    _calced,
    varNameSort
    _calcabc

    ))),
    "_calced","_calcabc"
    ),
    Slider4_11.Value = 0 || SetForRetirement = Switch(
    Slider4_11.Value,
    1,
    "Yes",
    2,
    Blank()
    ),
    Slider4_10.Value = 2 || Archived = Switch(
    Slider4_10.Value,
    1,
    "Yes",
    0,
    Blank()
    )
    )
    )

     

    THank you again!

     

     

  • WarrenBelz Profile Picture
    156,748 Most Valuable Professional on at

    Hi @ckserra33 ,

    Are _calcabc and _calced fields or variables and am I correct in my assumption of what you are trying to do?

  • ckserra33 Profile Picture
    421 on at

    Hi @WarrenBelz ,  _calced and _calcabc are added columns from the AddColumns formula.  They are not variables. They are only mentioned in the app in this gallery. And you are correct in your assumption on the filtering.  Thank you again!

    Chris

  • WarrenBelz Profile Picture
    156,748 Most Valuable Professional on at

    Hi @ckserra33 ,

    Firstly, you were missing a comma on this after varNameSort, but you still need to add another field if neither are true

    If(
     varNBVSort,
     _calced,
     varNameSort,
     _calcabc,
     YourOtherField
    )

    However please see how this works, although I have one question - why the two filters and not combined into one ?

    Filter(
     DropColumns(
     Sort(
     AddColumns(
     Search(
     Filter(
     AmusementAssets,
     TextBarcode = varBarcodeScanSSC &&
     (
     Checkbox15_1.Value || 
     GameAssetStatus <> "On Floor"
     ) &&
     (
     Dropdown8_5.Selected.Name = "All") || 
     GameAssetStatus = Dropdown8_5.Selected.Name
     ) &&
     CurrentStoreName = 
     Switch(
     varUser.Department,
     "6250",
     "Franklin-0038",
     varUser.OfficeLocation
     )
     ),
     tiGameName_6.Text,
     "cr3db_name",
     "cr3db_textbarcode",
     "cr3db_serialnumber"
     ),
     "_calced",
     Value('NBV-eliminate Negative'),
     "_calcabc",
     Text(TitleGame)
     ),
     If(
     varNameSort,
     _calcabc,
     _calced
     )
     ),
     "_calced",
     "_calcabc"
     ),
     Slider4_11.Value = 0 || 
     SetForRetirement = 
     Switch(
     Slider4_11.Value,
     1,
     "Yes",
     2,
     Blank()
     ) &&
     Slider4_10.Value = 2 || 
     Archived = 
     Switch(
     Slider4_10.Value,
     1,
     "Yes",
     0,
     Blank()
     )
    ) 

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • ckserra33 Profile Picture
    421 on at

    Hi @WarrenBelz Thank you again for your help!   So in adding this and actuating the icons to change between alphabetical and numeric sort, my gallery is changing, but its not changing totally, so its alphabetical for a bit, and then its not.  Same with NBV.  As far as the two filters, when I got help writing this, as its far past my skill level, I was told the 2 different filters were so the search function would work properly.  If it was all together it wouldnt work correctly.  

    Chris

  • WarrenBelz Profile Picture
    156,748 Most Valuable Professional on at

    Hi @ckserra33 ,

    I have to say firstly this is a very complex filter, with a second filter after the conditional sort. It is not uncommon for galleries to not completely resolve code of this complexity - I had a recent example on something smaller than yours.

    I have re-worked it a bit as below (DropColumns is not necessary, the filters should be together and I have moved all the calculation out of the filter), but it is impossible for me to test anything here.

    With(
     {
     wStore:
     Switch(
     varUser.Department,
     "6250",
     "Franklin-0038",
     varUser.OfficeLocation
     ),
     wRetire:
     Switch(
     Slider4_11.Value,
     1,
     "Yes",
     2,
     Blank()
     ),
     wArchive:
     Switch(
     Slider4_10.Value,
     1,
     "Yes",
     0,
     Blank()
     )
     },
     Sort(
     Search(
     AddColumns(
     Filter(
     AmusementAssets,
     TextBarcode = varBarcodeScanSSC &&
     (
     Checkbox15_1.Value || 
     GameAssetStatus <> "On Floor"
     ) &&
     (
     Dropdown8_5.Selected.Name = "All" || 
     GameAssetStatus = Dropdown8_5.Selected.Name
     ) &&
     CurrentStoreName = wStore &&
     (
     Slider4_11.Value = 0 || 
     SetForRetirement = wRetire
     ) &&
     (
     Slider4_10.Value = 2 || 
     Archived = wArchive
     )
     ),
     "_calced",
     Value('NBV-eliminate Negative'),
     "_calcabc",
     Text(TitleGame)
     ),
     tiGameName_6.Text,
     "cr3db_name",
     "cr3db_textbarcode",
     "cr3db_serialnumber"
     ),
     If(
     varNameSort,
     _calcabc,
     _calced
     )
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • ckserra33 Profile Picture
    421 on at

    Hi @WarrenBelz .  Thank you for your help!  I have taken your advice and I started from scratch in writing the formula.  Turns out I had way too much code in there for what I needed.  The new code works great, I couldnt have done it without your help.  Thank you again!

    Chris

  • WarrenBelz Profile Picture
    156,748 Most Valuable Professional on at

    Hi @ckserra33 ,

    So this is now solved (it solved what you asked in your post) ?

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 339 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 289

#3
Mohsin Ali Profile Picture

Mohsin Ali 228

Last 30 days Overall leaderboard