cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JSTechSand
Frequent Visitor

Matching numbers and random colors

What I have using MOD kind of works however I would like to randomize the colors of the odd numbers as well.  The goal is to quickly see color coded numbers in a details view.

 

The code below will match same Title (which is a number in this case) with the same color.  The Mod function pulls all of the evens and set's their colors based on matching Title.  The odd numbers are static one color, no randomizing (I would like to randomize this but match same Title colors).  Hopefully this makes sense.

 

This is what I have:

 

If(
Mod(
ThisItem.Title,
2
) = 0,
RGBA(256*Rand(), 256*Rand(), 256*Rand(), 1)
)

 

Here are the results

JSTechSand_0-1668541251208.png

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
v-bofeng-msft
Community Support
Community Support

Hi @JSTechSand ,

 

I assume there is a collection:

Collect(
    Mycollection,
    {Title:1234,ID:1},
    {Title:123451,ID:2},
    {Title:123451,ID:3},
    {Title:123451,ID:4},
    {Title:123452,ID:5},
    {Title:123453,ID:6},
    {Title:123453,ID:7},
    {Title:123454,ID:8}    
    )

You could try:

1\Set the gallery's items property to:

Ungroup(AddColumns(GroupBy(Mycollection,"Title","NewGroup"),"Color",RGBA(256*Rand(), 256*Rand(), 256*Rand(), 1)),"NewGroup")

2\Set the control's Fill property to:

If(
Mod(
ThisItem.Title,
2
) = 0,
RGBA(256*Rand(), 256*Rand(), 256*Rand(), 1),
ThisItem.Color
)

vbofengmsft_0-1668566583924.png

 

Best Regards,

Bof

 

View solution in original post

10 REPLIES 10
v-bofeng-msft
Community Support
Community Support

Hi @JSTechSand ,

 

I assume there is a collection:

Collect(
    Mycollection,
    {Title:1234,ID:1},
    {Title:123451,ID:2},
    {Title:123451,ID:3},
    {Title:123451,ID:4},
    {Title:123452,ID:5},
    {Title:123453,ID:6},
    {Title:123453,ID:7},
    {Title:123454,ID:8}    
    )

You could try:

1\Set the gallery's items property to:

Ungroup(AddColumns(GroupBy(Mycollection,"Title","NewGroup"),"Color",RGBA(256*Rand(), 256*Rand(), 256*Rand(), 1)),"NewGroup")

2\Set the control's Fill property to:

If(
Mod(
ThisItem.Title,
2
) = 0,
RGBA(256*Rand(), 256*Rand(), 256*Rand(), 1),
ThisItem.Color
)

vbofengmsft_0-1668566583924.png

 

Best Regards,

Bof

 

Thanks @v-bofeng-msft so the group works perfect, the rest of the columns stopped showing up...  Not sure what happened there?  This is an sp list.  Is there something I'm missing?  I'm also trying to sort them by a date field so this may be part of the issue?

 

Any ideas would be greatly appreciated!  Thanks. 

Hi @JSTechSand ,

 

Please show me more details. (detail settings, formula,screenshots)

 

Best Regards.

Bof

Hey @v-bofeng-msft no problem,  Thanks.

Here's what I have currently in items of the browse gallery:

 

Sort(
[@'Shower Department'],
'INSTALL DATE',
Ascending
)

 

The app is sorted by due date to keep the most important items on top.

 

When I use the code you provided linked to the sp list:

 

Ungroup(
AddColumns(
GroupBy(
[@'Shower Department'],
"Title",
"NewGroup"
),
"Color",
RGBA(
256 * Rand(),
256 * Rand(),
256 * Rand(),
1
)
),
"NewGroup"
)

 

Title and a few other columns show up, here's an example of before:

 

JSTechSand_0-1669089230798.png

And here is with the ungroup:

JSTechSand_1-1669089357655.png

Using this code:

JSTechSand_2-1669089389946.png

I hope this makes sense.  I haven't been able to apply the sort by date.  Can that be nested? Let me know if you need any additional information, and thanks for your help!

Hi @JSTechSand ,

 

The formula does not report an error, it seems that the error appears on other controls. Can you provide settings for these controls?

 

 

Best Regards,

Bof

@v-bofeng-msft I sent you a direct message with some more details, maybe due to using choice columns in the sp list?

Thanks for your help with this @v-bofeng-msft. There was a problem with the controls on my end, your solution worked out perfectly!

 

Here's an example, the commented control was the problem:

/ * "Small Parts: "& ThisItem.'STATUS - SMALL PARTS'.Value * /
"Small Parts: "& ThisItem.STATUS_x002d_SMALLPARTS.Value  <-- this was correct

 

Trying to figure out how to sort this by the Installdate column now.  

 

Any ideas?

Disregard, I figured out the sorting by date.  Thanks again!

 

Working groupby with sort:

Sort(Ungroup(AddColumns(GroupBy([@'Shower Department'],"Title","NewGroup"),"Color",RGBA(256*Rand(),256*Rand(),256*Rand(),1)),"NewGroup"),INSTALLDATE,Ascending)

Maybe not @v-bofeng-msft, the sort worked ok and didn't give me any errors, however the color function is no longer grouped.  Any ideas would be greatly appreciated! Thanks

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (4,369)