web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to cycle through a...
Power Apps
Answered

How to cycle through a table of colors?

(0) ShareShare
ReportReport
Posted on by 14

I have created a table of color values. I have re-purposed a gallery into a horizontal bar chart. I now want each of the bars (a control within each gallery item) of said chart to be a different color by cycling through the table. After the end of the table has been reached, it will reset back to the first item (color) in the table.

3-14-2023 2-13-36 PM.png
Categories:
  • subsguts Profile Picture
    1,259 Moderator on at

    This is a pretty complex question.  However, maybe I can provide some ideas.

     

    First, I would add a row number to each item in your gallery.  Here's a post that talks about how to do that: Power Apps Guide - Formulas - Generating Row Numbers - Power Apps Guide - Blog

    Next, I would set a variable like (Set VarNumberofColors, <equal to the count of the colors in your table>)

    Then to determine which color to use, I would take the row number and use the mod funciton like this.  Let's pretend there are 10 colors.

     

    Mod(ThisItem.RowNumber, VarNumberofColors) will return the index of the color you want, when you reach the 11th item in this example it will return a 1, which is back to the first color.  This will work to give you the index for any number of colors.

    Last, you'll need to add a index to your table (although there might be another way to do this), I think it's just easier to number  your colors with a second field in the table and then you can easily do a lookup on it to get the color.

    I hope this helps and please reply with specific issues you run into, but I believe you can use the above to get started down the path to the solution you are looking for.

  • Aschana1 Profile Picture
    14 on at

    Thank you for taking the time to respond. While the blog post link does not work, the post itself outlines an approach that I have seen elsewhere to some degree but barely comprehend. Thank you for breaking down the process into individual steps. My next step will be to figure out how to add row numbers.

  • subsguts Profile Picture
    1,259 Moderator on at

    I've not seen what you are trying to do exactly, but think it is possible.  As you work through the solution please post additional questions as well as what the end solution is so that we can all learn from it.  Thanks!

  • Aschana1 Profile Picture
    14 on at

    For a different section of my app, I have used the approach mentioned in this article (https://www.matthewdevaney.com/power-apps-display-a-user-photo-or-initials/#Assign-A-Fill-Color-For-The-Initials) however I am unsure how to repurpose this to iterate based on row number.

  • Verified answer
    subsguts Profile Picture
    1,259 Moderator on at

    This solution requires you to click a button to cause the effect.  I don't think that's what you wanted.  I believe you solution is not as complicated as this too.  

    1.  Add a new number field to your table of colors called it ColorIndex (done?) 

    2.  Add a row number to each value in your gallery call it GalleryRowNumber (done?) (use the link I sent you on how to do this)

    3.  Set a variable equal to the number of colors (or rows in this case) in your table of colors (done?).  Call the variable VarNumberofColors.  You can set this variable in the Startup of the App or the OnVisible of the screen.

    4.  In the Color property of the gallery to be Lookup(<your table of colors>, ColorIndex = Mod(ThisItem.RowNumber, VarNumberofColors), <name of color field>).  Check my syntax on this.  Also, make sure what's in your table are "Color.Red", "Color.Black", etc. for your varlues of the <name of color field>.

     

    I can't say that I've built this and tested it, but I believe this will get you to your solution.  If I have time I'll build out the code, but thinking you can probably get there with this?  

     

    Hope this helps.

  • Aschana1 Profile Picture
    14 on at

    Thank you, this approach worked for me. I was able to add row numbers to my gallery iteratively and then using a second table of colors, use Lookup() to match thisitem.ID with the color table's ID.

     

    Edit: I had to change the numbers on my table of colors (6 colors total) to 1, 2, 3, 4, 5, 0 instead of 1, 2, 3, 4, 5, 6 as Mod(ThisItem.ID, VarNumberofColors) returns 0 for item 6. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 402 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 296 Most Valuable Professional

Last 30 days Overall leaderboard