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 / IF statement works for...
Power Apps
Answered

IF statement works for true but not for fans with a ComboBox

(0) ShareShare
ReportReport
Posted on by 31

This is my formula: 

If(Toggle_Concern_Positive.Value,
SortByColumns(Filter('CombBox Student Behaviors', ID>0).'Positive Behaviors', "PositiveBehaviors", Ascending),
SortByColumns(Filter('CombBox Student Behaviors', ID > 0).'Concern Behaviors', "ConcernBehaviors", Ascending))

 

I am wanting to populate a ComboBox based on a Toggle Value. When it is true I see the Positive Behaviors, when the toggle is false I see the Concern Behaviors. PowerApps says the formula is correct. Each part of the If statement works independently. If I put a list using [ ] in the false statement it works. What am I missing?

Categories:
  • HamidBee Profile Picture
    932 Super User 2024 Season 1 on at

    It appears that you're trying to use the SortByColumns function within the "false" portion of your If statement, but it is not working as expected. One possible reason for this is that SortByColumns expects a table as its first argument, but you're providing it with a single column of data instead.

    Try changing your false statement to this: SortByColumns(Filter('CombBox Student Behaviors', ID > 0), "ConcernBehaviors", Ascending)

    This should work, as you are providing the SortByColumns function with the whole table and not just a single column.

     

    If my reply helped you, please give a 👍, & if it solved your issue, please 👍& Accept it as the Solution to help other community members find it more.

  • paguirre Profile Picture
    31 on at

    Thank you so much for your suggestion and insight.

    I made the changes as you suggested.

    If(Toggle_Concern_Positive.Value,
    SortByColumns(Filter('CombBox Student Behaviors', ID>0).'Positive Behaviors', "PositiveBehaviors", Ascending),
    SortByColumns(Filter('CombBox Student Behaviors', ID > 0), "ConcernBehaviors", Ascending))

    Unfortunately, the Positive Behaviors column appeared when the toggle was false. I didn't check but I bet it was sorted by the Concern Behavior column. I tried removing the ".'Positive Behaviors'" from the true statement, but it function the same. The toggle in true or false gave only the Positive Behaviors list.

  • Verified answer
    WarrenBelz Profile Picture
    156,956 Most Valuable Professional on at

    Hi @paguirre ,

    Two things here - if you are using SharePoint, the ID is always greater than 0, however your main issue is that the column name in the Table needs to be the same in both instances, so

    With(
     {
     wData:
     Filter(
     'CombBox Student Behaviors', 
     ID > 0
     )
     },
     SortByColumns(
     If(
     Toggle_Concern_Positive.Value,
     RenameColumns(
     wData,
     "PositiveBehaviors",
     "Value"
     ),
     RenameColumns(
     wData,
     "ConcernBehaviors",
     "Value"
     )
     )
     ).Value,
     "Value"
    )

    or if you do not need the ID filter

    SortByColumns(
     If(
     Toggle_Concern_Positive.Value,
     RenameColumns(
     'CombBox Student Behaviors',
     "PositiveBehaviors",
     "Value"
     ),
     RenameColumns(
     'CombBox Student Behaviors',
     "ConcernBehaviors",
     "Value"
     )
     ).Value,
    "Value"
    )

     

    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.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • paguirre Profile Picture
    31 on at

    Thanks again. Hoorah!!! Apparently I did not need the ID column. It was initially included to ensure all the items in the column were included. Best of success to you.
    Gratefully,

    Pablo

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 232 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 202 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 122

Last 30 days Overall leaderboard