cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jbrit2020
Super User
Super User

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.
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.
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

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.
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
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (1,398)