web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details
Power Apps - Building Power Apps
Answered

Change Color with "switch" and "in" function for one properties (fill)

Like (0) ShareShare
ReportReport
Posted on 3 Dec 2023 19:12:27 by 323

Hi all

 

I would like to change the container fill color based on the label text that contains an email address using the "in" function also like to use a switch function how could I use both for the fill properties for container?

 

code currently 

Switch(
 true,
 DateDiff(
 Today(),
 DatePicker1
 ) < 6,
 Color.DarkRed,
 DateDiff(
 Today(),
 DatePicker1
 ) > 6,
 Color.DarkGreen,
 DateDiff(
 Today(),
 DatePicker1
 ) = 6,
 Color.DarkGreen
)

moerah_0-1701630585546.png

 

 

Thank you 

I have the same question (0)
  • Verified answer
    LaurensM Profile Picture
    12,510 Moderator on 03 Dec 2023 at 20:49:33
    Re: Change Color with "switch" and "in" function for one properties (fill)

    Hi @moerah,

     

    Thank you for the additional info! The code below will first check whether that particular line contains a valid email format, if not then we go through the day colors. If I understand it correctly, a filled in email has priority over the date difference check.

     

    If(
     //Check whether the Text Input contains a valid email
     IsMatch(
     //Change to the correct control
     TextInput1.Text,
     "^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$"
     ),
     Color.Green,
     //If not, go through the DateDiff logic
     DateDiff(Today(), DatePicker1.SelectedDate) < 5,
     Color.Red,
     DateDiff(Today(), DatePicker1.SelectedDate) > 10,
     Color.Green,
     //Else (between 5 and 10 days)
     Color.Orange
    )

     

    If this solves your question, would you be so kind as to accept it as a solution & give it a thumbs up.

    Thanks!

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Telen Wang – Community Spotlight

We are honored to recognize Telen Wang as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 637 Most Valuable Professional

#2
stampcoin Profile Picture

stampcoin 570 Super User 2025 Season 2

#3
Power Apps 1919 Profile Picture

Power Apps 1919 473

Loading complete