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

Add column to a Collection by picking values on another Collection

I have a collection (groupedData) that groups and count identical items, and another collection (Colors) with color values. I never know how many items the groupedData collection will have, so depending how many rows it has it'll need to pick just the needed items from the Color collection, and add it as a new column:

ClearCollect(
    groupedData,
    SortByColumns(
        DropColumns(
            AddColumns(
                GroupBy(
                    AddColumns(
                        Filter(
                            'Catalog',
                            Year = ReviewYear
                        ),
                        "RO",
                        'Regional Office'.Value
                    ),
                    "RO",
                    "GroupedItems"
                ),
                "Count Value",
                CountRows(GroupedItems)
            ),
            "GroupedItems"
        ),
        "RO",
        Ascending
    )
);

Colors Collection:

ClearCollect(
    Colors,
 ["#FF6633", "#FFB399", "#FF33FF", "#FFFF99", "#00B3E6", 
		  "#E6B333", "#3366E6", "#999966", "#99FF99", "#B34D4D",
		  "#80B300", "#809900", "#E6B3B3", "#6680B3", "#66991A", 
		  "#FF99E6", "#CCFF1A", "#FF1A66", "#E6331A", "#33FFCC",
		  "#66994D", "#B366CC", "#4D8000", "#B33300", "#CC80CC", 
		  "#66664D", "#991AFF", "#E666FF", "#4DB3FF", "#1AB399",
		  "#E666B3", "#33991A", "#CC9999", "#B3B31A", "#00E680", 
		  "#4D8066", "#809980", "#E6FF80", "#1AFF33", "#999933",
		  "#FF3380", "#CCCC00", "#66E64D", "#4D80CC", "#9900B3", 
		  "#E64D66", "#4DB380", "#FF4D4D", "#99E6E6", "#6666FF"]
);

  How can achieve this? 

 

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenBelz
Super User
Super User

Hi @emfuentes27 ,

This blog of mine should assist you here. The below should give you an idea on structure, but note free-typed, so watch commas/brackets

With(
   {
      wColourNo:
      FirstN(
         Colors,
         CountRows(groupedData)
      )
   },
   With(
      {
         wGrouped: 
         ForAll(
            Sequence(
               CountRows(groupedData)
            ),
            Patch(
               Last(
                  FirstN(
                     groupedData,
                     Value
                  )
               ),
               {RowNo1: Value}
            )
         ),
         wColors: 
         ForAll(
            Sequence(
               CountRows(wColourNo)
            ),
            Patch(
               Last(
                  FirstN(
                     wColourNo,
                     Value
                  )
               ),
               {RowNo2: Value}
            )
         )
      },
      ClearCollect(
         colGroupedColors,
         AddColumns(
            wGrouped,
            "GroupColor",
            LookUp(
               wColors,
               RowNo2 = RowNo1
            ).Value
         )
      )
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

 

View solution in original post

1 REPLY 1
WarrenBelz
Super User
Super User

Hi @emfuentes27 ,

This blog of mine should assist you here. The below should give you an idea on structure, but note free-typed, so watch commas/brackets

With(
   {
      wColourNo:
      FirstN(
         Colors,
         CountRows(groupedData)
      )
   },
   With(
      {
         wGrouped: 
         ForAll(
            Sequence(
               CountRows(groupedData)
            ),
            Patch(
               Last(
                  FirstN(
                     groupedData,
                     Value
                  )
               ),
               {RowNo1: Value}
            )
         ),
         wColors: 
         ForAll(
            Sequence(
               CountRows(wColourNo)
            ),
            Patch(
               Last(
                  FirstN(
                     wColourNo,
                     Value
                  )
               ),
               {RowNo2: Value}
            )
         )
      },
      ClearCollect(
         colGroupedColors,
         AddColumns(
            wGrouped,
            "GroupColor",
            LookUp(
               wColors,
               RowNo2 = RowNo1
            ).Value
         )
      )
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

 

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.

Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

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 (3,124)