cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Maas
Frequent Visitor

Set color if another field is empty

If want to set the fill color of an 'rectangle1' to green, if another field 'Title'  is empty.

 

I tryed this: If(Title="", Color,Green, Color.Red)

and this If(IsEmpty(Tiltle.text), Color.Green, Color.Red)

both not doing the job.

 

What can I do to set the color of de Rectangle, when the Title is empty.

 

Any help?

 

1 ACCEPTED SOLUTION

Accepted Solutions

Thank you very much.

 

This does the job for me:

If(Len(ThisItem.Title)=0; Green; Red)

View solution in original post

8 REPLIES 8
Meneghino
Community Champion
Community Champion

Hi @Maas 

What you require is easily done, but the solution depends on specifics of your app.

 

Where is the rectangle?  On the screen or in the template of a gallery?

 

What do you mean by "another field"?   How do you choose which record of the data source, or is Title the name of a text box?

 

If Title really is a field, then what is the name of the data source containing this field?

 

Thanks

The Rectagle (Rectagle1) and the Title (Subtitle1) are in de Browsegallery1

 

BrowseGallery1:

 

Rectangle1 is left (black), Title is 'BIN'.

 

What I want is:

whentrhe  Title (hereunder BIN) (Field: Subtitle1) is blank/empty, then set fill Rectangle1 to Green else to Red.

 

pa1.png

 

Meneghino
Community Champion
Community Champion

If(IsBlank(ThisItem.Subtitle1), Green, Red)

This will test only blank.

 

If you also want to test for both blank and empty string ("") [they are not the same] then you need this

If(Len(ThisItem.Subtitle1)=0, Green, Red)

 

Please let me know how you get on

hmm.. not yet 🙂 Red

 

Field I want to check is Title (Subtitle1) See, hereunder

If this field is empty.

 

pa3.png

 

Then I select the Rectangle1 and type in 

pa2.png

 

Meneghino
Community Champion
Community Champion

Hi @Maas, we will get there.

 

Thanks for the screenshot, this makes it much clearer.  The field name is Title and you have a text box called Subtitle1 somewhere which could be a gallery or a display form.

Hence you are right that the expression needs to be ThisItem.Title

 

Now, I can think of a few possible issues for you to explore:

1) You are not in an English locale, therefore you may need to use semi-colon ; instead of comma , in the above expressions

2) The names of colours may also not work, so try RGBA expressions , hence something like this:

If(Len(ThisItem.Subtitle1)=0; RGBA( 0; 128; 0; 1 );  RGBA( 255; 0; 0; 1 ))

3) If it is a form, then you may need Parent instead of ThisItem

 

If this does not work, then just try to set the colour without the If statement to see what happens.  Please let me know which colour expression works for your locale.

 

Thanks.

Thank you very much.

 

This does the job for me:

If(Len(ThisItem.Title)=0; Green; Red)


@Meneghino wrote:
If(IsBlank(ThisItem.Subtitle1), Green, Red)

This will test only blank.

 

If you also want to test for both blank and empty string ("") [they are not the same] then you need this

If(Len(ThisItem.Subtitle1)=0, Green, Red)

 

Please let me know how you get on


 

How about:

 

If(IsBlank(Trim(ThisItem.Title)), Green, Red)

 

 

to check for both blank and empty string?

Meneghino
Community Champion
Community Champion

hi @flyte

 

Yes, your expression would work, but it would also be green for " " and any number of spaces.  This may or may not be what is needed.

 

It also appears that IsBlank("") is true, so IsBlank returns true for zero-length strings also.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,007)