cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jbrit2020
Continued Contributor
Continued Contributor

Dynamic Conditional color formatting in a Gallery

Hi, I'm in a situation where I need a different colour to be automatically attributed based on a condition.

 

I do not want to hardcode the conditions because they might change weekly.

 

I need the app to look at everything in a gallery that says "Commercial" and fill it Green, and I want it to look at a label that says Finance and turn Red. That is easy in itself with an if statement. but the issue is, Next week, a new department will be added and it's called "Property", I don't want to have to go back to the app and hardcode Property in the app.

 

In reality what I need is powerapps to group everything in their specific buckets based on the Department column, and spit out a colour per department, so everytime a new department is added or name is changed I dont have to go back and hardcode it again.

 

any ideas on how to achieve this?

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@jbrit2020 

You will need to have a separate list (or augment an existing) to store the department names and colors.

So, let's say you now have a list with a Department Name and color such as this:

Title Color
Commercial Green
Finance Red
Property Purple

 

Since this is relatively static information, I would have the OnStart of the app gather the information with:

Set(departmentColors, yourDepartmentList)

 

Now for the Gallery control Color property:

   ColorValue(Coalesce(LookUp(departmentColors, Title=Self.Text, Color), "Black"))

 

This will lookup the department in the table variable and return the color based on the text of the control.  If not found, it will default to Black.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

3 REPLIES 3
RandyHayes
Super User
Super User

@jbrit2020 

You will need to have a separate list (or augment an existing) to store the department names and colors.

So, let's say you now have a list with a Department Name and color such as this:

Title Color
Commercial Green
Finance Red
Property Purple

 

Since this is relatively static information, I would have the OnStart of the app gather the information with:

Set(departmentColors, yourDepartmentList)

 

Now for the Gallery control Color property:

   ColorValue(Coalesce(LookUp(departmentColors, Title=Self.Text, Color), "Black"))

 

This will lookup the department in the table variable and return the color based on the text of the control.  If not found, it will default to Black.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
jbrit2020
Continued Contributor
Continued Contributor

Hi @RandyHayes, so this would be updated manually whenever a user adds a new department correct? They would also have to select a colour for the new department correct?

 

This selection populates then the DepartmentList, and whenever a new record falls under certain department it will take it's colour.

 

Can a colour picker be used for that purpose when a user is adding something to the departmentlist?

RandyHayes
Super User
Super User

@jbrit2020 

Yes, your assumptions are correct.  A user would need to manually edit the department list and then the app would reflect those values (after app restart). 

 

As for the picker for the colors, they would be valid color names only in text format.  If you want a color picker, then you would be talking about another app, or a part of your existing app to "maintain" that list of departments.  Certainly possible.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (4,480)