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
Maas
Frequent Visitor

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

Maas
Frequent Visitor

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

Maas
Frequent Visitor

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.

Maas
Frequent Visitor

Thank you very much.

 

This does the job for me:

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

View solution in original post


@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
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Did you miss the call? Check out the recording here!

Top Solution Authors
Top Kudoed Authors
Users online (4,544)