cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Create a color value per Distinct values from a collection

Hi, I have a collection called "ListItems" with a nested collection called "Phase" that I want to give a color per Distinct "Phase" value.

I am collecting a List from a sharepoint site like follows:

 

ClearCollect(ListItems,'Project Schedule')

 

Capture01.JPG

 

Capture02.JPG

 

 

 

 

 

 

 

 

 

I am Getting the Distinct values with the following applied to the gallery item in the top left of the below image:

 

Distinct(ListItems, Phase.Value)

 

But I want to take it a step further by applying a ColorValue to each of these values.

Ideally I want to add it to the collection "ListItems" for each unique ListItems.Phase value. Because I want to apply this to a Gantt Chart for all items that are under that phase. (Gantt Chart is below showing what I want to achieve with colors for each phase):

Gantt-color.jpg

 Any help would be appreciated. This is based on what I have learnt from @Mr-Dang-MSFT 's Gantt Chart idea.

 

-EDIT- I want to cycle through a list of predefined RGB colors shown below. If it gets to the end of the list it just starts from the beginning again.

[{0, 127, 175},{95, 75, 139},{255, 176, 37},{215, 45, 92},{255, 121, 19},{183, 108, 164},{214, 180, 180},{196, 143, 101},

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

I figured it out in the end (walking away and coming back with a fresh perspective helps..). After creating the Color table.

ClearCollect(Colors,{ColorIndex:0,Color:RGBA(0,127,175,1)},{ColorIndex:1,Color:RGBA(95,75,139,1)},{ColorIndex:2,Color:RGBA(255,176,37,1)},{ColorIndex:3,Color:RGBA(215,45,92,1)},{ColorIndex:4,Color:RGBA(255,121,19,1)},{ColorIndex:5,Color:RGBA(183,108,164,1)},{ColorIndex:6,Color:RGBA(214,180,180,1)},{ColorIndex:7,Color:RGBA(196,143,101,1)});

 For clarity, I created a Table that combined "Color" by "Phases" by an Index comparison or "LookUp".

ForAll(Distinct(ListItems, Phase.Value), Collect(DistinctPhases, {Value: Result, PhaseIndex: CountRows(DistinctPhases)}));
ClearCollect(IndexedPhases, AddColumns(DistinctPhases,"PhaseColor", LookUp(Colors, PhaseIndex=ColorIndex, Color)));

 Then used "AddColumns" to the embedded Gallery "GalleryTasksGantt" I originally had issues with.

AddColumns(IndexedPhases, "col",LookUp(IndexedPhases, Value=(ThisItem.Phase.Value),PhaseColor))

 

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

@simondpalmer You should rewrite Colors like this and assign a color an index.

 

 

 

 

ClearCollect(Colors,{ColorIndex:0,Color:RGBA(0,127,175,1)},{ColorIndex:1,Color:RGBA(95,75,139,1)},{ColorIndex:2,Color:RGBA(255,176,37,1)},{ColorIndex:3,Color:RGBA(215,45,92,1)},{ColorIndex:4,Color:RGBA(255,121,19,1)},{ColorIndex:5,Color:RGBA(183,108,164,1)},{ColorIndex:6,Color:RGBA(214,180,180,1)},{ColorIndex:7,Color:RGBA(196,143,101,1)}); ClearCollect(Phase, Distinct(ListItems, Phase.Value))

 

 

 

 

And then you can create an indexed list of distinct phases

 

 

ClearCollect(DistinctPhases, Distinct(ListItems, Phase.Value));
ForAll(DistinctPhases, Collect(IndexedPhases, {Value: Result, PhaseIndex: CountRows(IndexedPhases)});

 

 

 

And finally, you can use the formula for the items property of the top left distinct phases gallery:

 

 

AddColumns(IndexedPhases, "Color", Lookup(Colors, ColorIndex=Mod(PhaseIndex, CountRows(Colors))))

 

 

 

Now you are free to use this collection as a lookup for your main gallery.

Lookup(IndexedPhases, Phase=ThisItem.Phase.Value, Color)

 

Best,
Zabi
Mark this post as a solution, or kudo it if you found it be helpful. You can choose more than one answer as solutions, including your own answer. 🙂

Thank you for your reply. So I put all of that together, amongst other irrelevant collections, as follows on home screen "On Visible":

ClearCollect(Colors,{ColorIndex:0,Color:RGBA(0,127,175,1)},{ColorIndex:1,Color:RGBA(95,75,139,1)},{ColorIndex:2,Color:RGBA(255,176,37,1)},{ColorIndex:3,Color:RGBA(215,45,92,1)},{ColorIndex:4,Color:RGBA(255,121,19,1)},{ColorIndex:5,Color:RGBA(183,108,164,1)},{ColorIndex:6,Color:RGBA(214,180,180,1)},{ColorIndex:7,Color:RGBA(196,143,101,1)});
ClearCollect(ProjectFinancials, Blank());
ClearCollect(WIPMonth, PA_WIP_GetMonth.Run());
ClearCollect(ListItems,'Project Schedule');
ClearCollect(DistinctPhases, Distinct(ListItems, Phase.Value));
ForAll(DistinctPhases, Collect(IndexedPhases, {Value: Result, PhaseIndex: CountRows(IndexedPhases)}));

Which works fine. 

Then for the gallery at the top left I use the following:

AddColumns(IndexedPhases, "Color", LookUp(Colors, Color=Mod(ColorIndex, CountRows(Colors))))

 

This comes up with an error message that "Color" is not a relevant color when used as "Fill" for an item inside the gallery:

ThisItem.Color

What have I done wrong? @Anonymous 

And how could I use this "Lookup" in my other Gallery which is pulling data from the original ListItems collection. That has the phase under ListItem.Phase.

The collections I have are as follows:

Capture-schedule01.JPGCapture-schedule02.JPGCapture-schedule03.JPG

ListItemsListItems

Anonymous
Not applicable

@simondpalmer  I believe you made a mistake here:

AddColumns(IndexedPhases, "Color", LookUp(Colors, Color=Mod(ColorIndex, CountRows(Colors))))

It should be:

AddColumns(IndexedPhases, Lookup(Colors, ColorIndex=Mod(PhaseIndex, CountRows(Colors))))

 

And then in your other gallery, you can do 

Lookup(IndexedPhases, Phase=ThisItem.Phase.Value, Color)

 

Best,
Zabi
Mark this post as a solution, or kudo it if you found it be helpful. You can choose more than one answer as solutions, including your own answer. 🙂

Thanks for the reply,It still doesn't work as it is expecting 3 arguments and has only received 2.

AddColumns(IndexedPhases, LookUp(Colors, ColorIndex=Mod(PhaseIndex, CountRows(Colors))))

I guess that is why I added "Colors" as a <column name>

Anonymous
Not applicable

Sorry, I made a mistake while correcting yours:

AddColumns(IndexedPhases, "Color", Lookup(Colors, ColorIndex=Mod(PhaseIndex, CountRows(Colors))))

 

The mistake you made was in this part of the formula:

LookUp(Colors, Color=Mod(ColorIndex, CountRows(Colors))

 It should be PhaseIndex instead of ColorIndex. Everything else is correct.

 

Best,
Zabi
Mark this post as a solution, or kudo it if you found it be helpful. You can choose more than multiple answers as solutions, including your own answer. 🙂

But you were right in adding the "Colors" column as a second argument. I am going to edit the original post to highlight that.

Thank you so much that worked for the top left Gallery I just had to add for the "Fill" to be

ThisItem.Color.Color

After the "Items" for the gallery is set to 

AddColumns(IndexedPhases, "Color", LookUp(Colors, ColorIndex=Mod(PhaseIndex, CountRows(Colors))))

----------

However, the main Gallery (GalleryTasks) below circled in red I am still having difficulty as it has an embedded horizontal gallery (GalleryTasksGantt) circled in blue to create the blue bars shown below

 

Capture.JPG

 

 As you can see I have the "Items" set for GalleryTasksGantt as

AddColumns(DateRange,"vis",Date>=(ThisItem.StartDate) && Date<=(ThisItem.DueDate))

(This provides a column called vis to turn on and off the blue bars as they correspond to a DateRange collection.)

The GalleryTasks gallery Items is set to

ListItems

How can I change the blue bar colors to match the Phase value for each of these Tasks?

I figured it out in the end (walking away and coming back with a fresh perspective helps..). After creating the Color table.

ClearCollect(Colors,{ColorIndex:0,Color:RGBA(0,127,175,1)},{ColorIndex:1,Color:RGBA(95,75,139,1)},{ColorIndex:2,Color:RGBA(255,176,37,1)},{ColorIndex:3,Color:RGBA(215,45,92,1)},{ColorIndex:4,Color:RGBA(255,121,19,1)},{ColorIndex:5,Color:RGBA(183,108,164,1)},{ColorIndex:6,Color:RGBA(214,180,180,1)},{ColorIndex:7,Color:RGBA(196,143,101,1)});

 For clarity, I created a Table that combined "Color" by "Phases" by an Index comparison or "LookUp".

ForAll(Distinct(ListItems, Phase.Value), Collect(DistinctPhases, {Value: Result, PhaseIndex: CountRows(DistinctPhases)}));
ClearCollect(IndexedPhases, AddColumns(DistinctPhases,"PhaseColor", LookUp(Colors, PhaseIndex=ColorIndex, Color)));

 Then used "AddColumns" to the embedded Gallery "GalleryTasksGantt" I originally had issues with.

AddColumns(IndexedPhases, "col",LookUp(IndexedPhases, Value=(ThisItem.Phase.Value),PhaseColor))

 

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!   This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions in the Forums to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber of SolutionsSuper UsersNumber of Solutions @anandm08  23 @WarrenBelz  31 @DBO_DV  10 @Amik  19 AmínAA 6 @mmbr1606  12 @rzuber  4 @happyume  7 @Giraldoj  3@ANB 6 (tie)   @SpongYe  6 (tie)     Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersSolutionsSuper UsersSolutions @anandm08  10@WarrenBelz 25 @DBO_DV  6@mmbr1606 14 @AmínAA 4 @Amik  12 @royg  3 @ANB  10 @AllanDeCastro  2 @SunilPashikanti  5 @Michaelfp  2 @FLMike  5 @eduardo_izzo  2   Meekou 2   @rzuber  2   @Velegandla  2     @PowerPlatform-P  2   @Micaiah  2     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 3:Community MembersSolutionsSuper UsersSolutionsPower Apps anandm0861WarrenBelz86DBO_DV25Amik66Michaelfp13mmbr160647Giraldoj13FLMike31AmínAA13SpongYe27     Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 4:Community MembersSolutionsSuper UsersSolutionsPower Apps DBO-DV21WarranBelz26Giraldoj7mmbr160618Muzammmil_0695067Amik14samfawzi_acml6FLMike12tzuber6ANB8   SunilPashikanti8

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (2,271)