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?
Solved! Go to Solution.
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.
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.
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?
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.
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
User | Count |
---|---|
179 | |
94 | |
63 | |
61 | |
58 |
User | Count |
---|---|
246 | |
165 | |
91 | |
76 | |
76 |