cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
stefansc
Resolver I
Resolver I

Get sum of records from one collection to an additional column in another collection

Hi all,

 

I have a problem to add a column to a collection containing a CountRows from another collection.

 

There are two collections:

colOrders

 

 

ClearCollect(
    colOrders,
    Sort(
        Distinct(
            Orders,
            OrderNumber
        ),
        ThisRecord.Result,
        Ascending
    )
);

 

 

This results in a collection like:

Result:

2022-123

2022-124

2022-125


colOrderDetails

 

 

ClearCollect(
    colOrderDetails,
    OrderDetails
);

 

 

This results in a collection like:

OrderNumberOrderDetail
2022-123Order detail 1
2022-123Order detail 2
2022-124Order detail 3
2020-125Order detail 4

 

I want to add a new column "Counter" to colOrders which counts the number of order details, so in this example it should look like:

ResultCounter
2022-1232
2022-1241
2022-1251

 

I already tried the following code:

 

 

ClearCollect(
    tempOrders,
    colOrders,
        AddColumns(
        colOrderss,
        "Counter",
        0)

);
ForAll(
    tempEnvironments,
    Counter = CountRows(
        Filter(
            colOrderDetails,
            ThisRecord.OrderNumber = Result
        )
    )
)

 

 

But even in the first ClearCollect, the column is added but without any value.

Also in the ForAll statement, it doesn't work.

Any idea woul be appreciated.

 

Best

 

Stefan

1 ACCEPTED SOLUTION

Accepted Solutions

HI,

this works:

ClearCollect(
    tempOrders,
    AddColumns(
        GroupBy(
            OrderDetails,
            "Ordernumber",
            "Orderdetails"
        ),
        "Counter",
        CountRows(ThisRecord.Orderdetails)
    )
)

 

 

View solution in original post

3 REPLIES 3
WarrenBelz
Super User
Super User

Hi @stefansc ,

Try this

ClearCollect(
   tempOrders,
   AddColumns(
      GroupBy(
         "OrderNumber",
         "Data"
      ),
      "Counter",
      CountRows(Data)
   )
)

 

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

HI,

this works:

ClearCollect(
    tempOrders,
    AddColumns(
        GroupBy(
            OrderDetails,
            "Ordernumber",
            "Orderdetails"
        ),
        "Counter",
        CountRows(ThisRecord.Orderdetails)
    )
)

 

 

Hi @stefansc ,

Yes - another version of the same structure.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (3,658)