Skip to main content
Community site session details

Community site session details

Session Id : 91AV6vEp0UZGt6ArMR2EUm
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 

  • moerah Profile Picture
    323 on 03 Dec 2023 at 21:29:08
    Re: Change Color with "switch" and "in" function for one properties (fill)

    Amazing!!! just what I needed 

     

    moerah_0-1701638708322.png

    just did a little tweak 

     

    thank you so much!!!

     

  • 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!

  • moerah Profile Picture
    323 on 03 Dec 2023 at 20:20:44
    Re: Change Color with "switch" and "in" function for one properties (fill)

    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 

  • LaurensM Profile Picture
    12,510 Moderator on 03 Dec 2023 at 19:43:29
    Re: Change Color with "switch" and "in" function for one properties (fill)

    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!

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410 Super User 2025 Season 2

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 2

Loading complete