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 / Filtering with Or oper...
Power Apps
Answered

Filtering with Or operator

(0) ShareShare
ReportReport
Posted on by 38

Greetings - I am stuck with a Filtering issue and would appreciate any advice pls. In PowerApps I am filtering a collection (from SharePoint List) by document chapters, and the sorted results are to be shown inside a combo box. Some of the documents are lengthy with chapters that do not sort logically. For these I have created a simple "ChapterSort" column with a number to determine the sort order. In my statement I am able to apply the Sort and Filter to the first two documents I have listed and separated with the 'Or' operator, my issue is that the same sort operation does not seem to be applied to the third subsequent document "Doc3". I am wondering if simplifying/altering the filter statement below might help?:-

 

 

If(
 varPlanSelected = "Doc1" Or varPlanSelected = "Doc2" Or varPlanSelected = "Doc3",
 Sort(
 Distinct(
 Filter(
 colSMERtrat,
 Year = ddDateList.Selected.Value
 ),
 PlanChapHead
 ),
 "ChapterSort",
 SortOrder.Ascending
 ),
 Sort(
 Distinct(
 colSMERtrat,
 PlanChapHead
 ),
 Value,
 SortOrder.Ascending
 )
)

 

 

Categories:
I have the same question (0)
  • Michael E. Gernaey Profile Picture
    53,974 Moderator on at

    Hi @ThenewThom 

     

    Why did you wrap it in an And? You dont need that. since its an Or Situation either do Or( or like you did use Or or (no pun lol) ||

     

    Also, just for future reference as thats hard to read, use the </> Code Snippet insert so its formatted and much easier hehe for us to read and follow. I hate having to paste it into the code window and reformatting it so I can read it.

     

    Now you said it doesn't work when its Doc3. I dont see any code that should fail, so that tells me that its not getting set to Doc3.

     

    Can you put a Text Label on the screen, and set it Text to varSelected and make 100% it says Doc3 without any spaces etc. (so do like he below in your Text label.

     

    "-" & varSelected & "-"

     

     
    If I have helped you, I would really appreciate if you please Mark my answer as Resolved/Answered, and give it a thumbs up, so it can help others

    Cheers

    Thank You
    Michael Gernaey MCT | MCSE | MCP | Self-Contractor| Ex-Microsoft
    https://gernaeysoftware.com
    LinkedIn: https://www.linkedin.com/in/michaelgernaey

  • Verified answer
    CU-18081211-6 Profile Picture
    9,270 Moderator on at

    @ThenewThom ,

    In the true branch of If condition:

     

    Sort(
     Distinct(
     Filter(
     colSMERtrat,
     Year = ddDateList.Selected.Value
     ),
     PlanChapHead
     ),
    "ChapterSort",
    SortOrder.Ascending
    )

     

    Using Sort() function with string "ChapterSort" (this is not the column name) although seems to be a legitim and corect formula, actually do nothing and the table remains "unharmed".

    Using SortByColumns() function with "ChapterSort" in your formula it will throw a syntax error, because based on your formula a "ChapterSort" column does not exist. That's because you use there a Distinct() function and the outputs of that function is a single table column with "Value" named column. 

     

    What it might work is:

     

    With(
     {
     baseSelection: 
     Filter(colSMERtrat,Year = ddDateList.Selected.Value)
     },
    If(
     varPlanSelected in ["Doc1","Doc2","Doc3"],
     Distinct(
     Sort( 
     baseSelection,
     ChapterSort,
     SortOrder.Ascending
     ),
     PlanChapHead
     ),
     Distinct(
     Sort(
     baseSelection,
     PlanChapHead,
     SortOrder.Ascending
     ),
     PlanChapHead
     )
     )
    )

     

     Hope it helps !

  • ThenewThom Profile Picture
    38 on at

    Thanks Mike I have updated the code snippet and I also added the details that I have the sort/filtered results showing in a combo-box. I double-checked and yes it is picking up the correct doc3

  • ThenewThom Profile Picture
    38 on at

    Thanks very much - yes that worked perfectly!

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 547

#2
WarrenBelz Profile Picture

WarrenBelz 444 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 322

Last 30 days Overall leaderboard