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 / Change Color with "swi...
Power Apps
Answered

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

(0) ShareShare
ReportReport
Posted on by 327

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 

Categories:
I have the same question (0)
  • LaurensM Profile Picture
    12,516 Moderator on at

    Hi @moerah😊

     

    Your current code can be shortened to:

    If(
     DateDiff(Today(), DatePicker1.SelectedDate) < 6,
     Color.DarkRed,
     Color.DarkGreen
    )

     

    In order to extend the code with the email label, would it be possible to provide some additional info on what you would like to achieve?

     

    Thanks!

  • moerah Profile Picture
    327 on at

    thanks for the reply and tip

     

    goal is to have the user input an email address which then changes the colour of the container fill to green while having the switch function sort of like concatenate.

     

    separate note:

    how can i have 3 changes of color e.g

    <5 days its red

    between 5 and 10 its orange

    >10 its green 

     

    thank you 

  • Verified answer
    LaurensM Profile Picture
    12,516 Moderator on at

    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!

  • moerah Profile Picture
    327 on at

    Amazing!!! just what I needed 

     

    moerah_0-1701638708322.png

    just did a little tweak 

     

    thank you so much!!!

     

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!

Leaderboard > Power Apps

#1
Haque Profile Picture

Haque 94

#2
WarrenBelz Profile Picture

WarrenBelz 82 Most Valuable Professional

#3
Kalathiya Profile Picture

Kalathiya 38 Super User 2026 Season 1

Last 30 days Overall leaderboard