web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Power Apps if/switch s...
Power Apps
Unanswered

Power Apps if/switch statements

(0) ShareShare
ReportReport
Posted on by 17

I have a Powerapp that is connected to a SharePoint List, I'm trying to change the color of a gallery icon based on three things:

1) if the status is Yes -P, Yes -M, or Yes -J then show the checkbadge icon in green

2) if the status is No then show the cancelbadge in red

3) If Date 2 is empty but the status is Yes -P, Yes -M, or Yes -J show the checkbadge icon in yellow

 

I have tried to use many different if's over the last few days. I have it working to show the First two items with the switch, but the third item is where I'm having difficulties. Below is what I have for code on the color of the icon badge:

 

Switch(ThisItem.'Status'.Value,
"Yes - P", Color.Green,
"Yes - M",Color.Green,
"Yes - J",Color.Green,
Color.Red)

 

Any help would be greatly appreciated.

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @jcochrane 

    Please consider changing your Formula to the following:

    If(ThisItem.Status.Value = "No", Red,
     IsBlank(Date2), Yellow,
     Green
    )

    Since you seem to indicate that the Value will either be Yes (with more info) or No, then first check for No...you have one condition for that - Red.

    Otherwise, you know now that it is not No, so check the Date.  If it is blank, then Yellow.  Everything else evaluates to Green.

     

    I hope this is helpful for you.

  • jcochrane Profile Picture
    17 on at

    Thank you for this, I have one more question. If I have multiple No's/None to show as red in item 2 from above how would I modify this to work? For example

    No - M, No - R, None as the options?

  • Verified answer
    RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @jcochrane 

    If that is the case, you can just check if it starts with No.

    Ex:

    If(StartsWith(ThisItem.Status.Value, "No"), Red,
     IsBlank(Date2), Yellow,
     Green
    )
  • jcochrane Profile Picture
    17 on at

    That did it, Thank you very much!

  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @jcochrane 

    Happy to help!! 

  • jcochrane Profile Picture
    17 on at

    Just for my records, (because I think I can see needing to do this with another date field) what would the If statement look like for that, would the below work? 

     

    If(StartsWith(ThisItem.Status.Value, "No"), Red,
    IsBlank(Date2 || Date 3), Yellow,
    Green
    )

     

    Thanks for the help, I'm just staring out trying Powerapps.

  • Verified answer
    RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @jcochrane 

    Actually you would need to specify two functions for that.

    The formula would be:

    If(StartsWith(ThisItem.Status.Value, "No"), Red,
     IsBlank(Date2) || IsBlank(Date3), Yellow,
     Green
    )
  • jcochrane Profile Picture
    17 on at

    Great, thank you again. Would you be able to explain the difference? So I have a better understanding on why my code wouldn't of worked?

  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @jcochrane 

    Your Formula would not have worked because you were testing to see if the Logical Boolean OR of Date2 and Date3 was blank.  This would never be because Date2 and Date3 are dates or empty, not Boolean true or false.

    What you want to OR together is the true or false result of IsBlank against a single date/column.  

    So, IsBlank(Date2 || Date3) will cause the evaluation to logically OR the two dates together and then IsBlank would look at the result of that OR to see if it is blank...which it would not be.  It would really not be valid, but if anything it would always be false - date or no date.  So, IsBlank would always return false because a Boolean true or false is not blank.

     

    hopefully that is clear and helpful.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard