Skip to main content

Notifications

Community site session details

Community site session details

Session Id : /jAjCNdQHw14XaLeD/XXoQ
Power Apps - Building Power Apps
Answered

Power Apps if/switch statements

Like (0) ShareShare
ReportReport
Posted on 20 Dec 2021 21:11:29 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.

  • RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on 21 Dec 2021 at 18:39:51
    Re: Power Apps if/switch statements

    @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.

  • jcochrane Profile Picture
    17 on 21 Dec 2021 at 18:14:15
    Re: Power Apps if/switch statements

    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?

  • Verified answer
    RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on 21 Dec 2021 at 18:01:09
    Re: Power Apps if/switch statements

    @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 21 Dec 2021 at 17:00:43
    Re: Power Apps if/switch statements

    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.

  • RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on 20 Dec 2021 at 21:43:08
    Re: Power Apps if/switch statements

    @jcochrane 

    Happy to help!! 

  • jcochrane Profile Picture
    17 on 20 Dec 2021 at 21:37:33
    Re: Power Apps if/switch statements

    That did it, Thank you very much!

  • Verified answer
    RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on 20 Dec 2021 at 21:31:18
    Re: Power Apps if/switch statements

    @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 20 Dec 2021 at 21:29:05
    Re: Power Apps if/switch statements

    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?

  • RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on 20 Dec 2021 at 21:19:43
    Re: Power Apps if/switch statements

    @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.

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Building Power Apps

#1
MS.Ragavendar Profile Picture

MS.Ragavendar 20

#2
BCBuizer Profile Picture

BCBuizer 10 Super User 2025 Season 1

#2
LC-26081402-0 Profile Picture

LC-26081402-0 10

Overall leaderboard