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 / Create 1 or more colle...
Power Apps
Suggested Answer

Create 1 or more collections / power automate calls (with collection) depending on amount selected

(1) ShareShare
ReportReport
Posted on by 80
I've got a PowerApp which is integrated in a PowerBI.
In the PowerBI I can select records until a max of 1000 (which is still the max for the integration i think).
In the PowerApp I am displaying the records in a gallery and I should be able to add a remark in 1 field and pass all as a json to a power automate flow.
As the flow will trigger a HTTP Call, I need to send batches of max 250 records. 

First I thought I had a solution (which was terrible, but worked, but apparently it doesnt work....)
In this case I would create a collection of the first 200 records and send this to my power automate. (also have it for third, fourth and fifth)
This works for my 1000 records, but when only 3 items are in the gallery it also executes this for all 5 galleries. 
There will be plenty of ideas for this i guess, but none of them come into my mind. Someone got an idea? 
 
If(IsError(ClearCollect(colFirst200ListItem,FirstN(ForAll(Gallery2.AllItems,{dataProcessingID:DataProcessingID,productID:ProductID,approverEmail:User().Email,userRemark:TextInput1_1.Text,approvalStatus:"Rejected",pricelistType:"Vendor",approvalTime:Text(Now(),DateTimeFormat.UTC)}),200))
),Notify("Error: Could not create the collection", NotificationType.Error));
If(CountRows(colFirst200ListItem)>0,
If(IsError(SendtoAPI.Run(JSON(colFirst200ListItem,JSONFormat.IgnoreBinaryData & JSONFormat.IgnoreUnsupportedTypes))),
Notify("Unexpected error happened, please send the following to : ",NotificationType.Error),Notify("Message sent successful!",NotificationType.Success););
);
If(IsError(ClearCollect(colSecond200ListItem,FirstN(LastN(ForAll(Gallery2.AllItems,{dataProcessingID:DataProcessingID,productID:ProductID,approverEmail:User().Email,userRemark:TextInput1_1.Text,approvalStatus:"Rejected",pricelistType:"Vendor",approvalTime:Text(Now(),DateTimeFormat.UTC)}),400),200))
),Notify("Error: Could not create the collection", NotificationType.Error));
If(CountRows(colSecond200ListItem)>0,
If(IsError(SendtoAPI.Run(JSON(colSecond200ListItem,JSONFormat.IgnoreBinaryData & JSONFormat.IgnoreUnsupportedTypes))),
Notify("Unexpected error happened, please send the following to : ",NotificationType.Error),Notify("Message sent successful!",NotificationType.Success););
);
 
Summary: I've got a gallery with 0-1000 records. When selecting a few it should create 1 collection and send it to powerbi, when selecting > 250 records it should send 2-5 collections to power automate. How can i create this in a much smarter and better way?
Categories:
  • Suggested answer
    RahulAnsari37 Profile Picture
    86 on at

    Hey,

    You are running into a classic Power Apps quirk! The reason your flow runs multiple times for just 3 items is because of how LastN() behaves. If you ask for LastN(collection, 400) and there are only 3 items, Power Apps just returns those same 3 items. Then your FirstN() grabs them again. Your CountRows check stays above 0, and it fires the flow over and over with duplicate data.

    The "smarter and better way" is to stop trying to chunk the data inside Power Apps. Instead, send all the records in one single JSON payload to Power Automate, and let Power Automate do the batching.

    Power Automate has a brilliant, native chunk() expression designed exactly for this.

    Step 1: Simplify your Power Apps code
    Just create a single collection of all your items and send it to the flow once.
     

    ClearCollect(
        colAllItems,
        ForAll(
            Gallery2.AllItems,
            {
                dataProcessingID: DataProcessingID,
                productID: ProductID,
                approverEmail: User().Email,
                userRemark: TextInput1_1.Text,
                approvalStatus: "Rejected",
                pricelistType: "Vendor",
                approvalTime: Text(Now(),DateTimeFormat.UTC)
            }
        )
    );
    
    If(
        !IsError(SendtoAPI.Run(JSON(colAllItems, JSONFormat.IgnoreBinaryData & JSONFormat.IgnoreUnsupportedTypes))),
        Notify("Message sent successful!", NotificationType.Success),
        Notify("Unexpected error happened.", NotificationType.Error)
    );

    Step 2: Chunk the data in Power Automate

    1. In your flow, take that JSON string from Power Apps and use a Parse JSON action so the flow recognizes it as an array.

    2. Add an Apply to each loop.

    3. Instead of looping through the raw array, click into the input box and enter this expression:
      chunk(body('Parse_JSON'), 250) (Note: replace body('Parse_JSON') with your actual dynamic content array).

    4. Put your HTTP action inside this loop.

    Why this is perfect:
    The chunk() expression automatically splits your massive array into sub-arrays of 250 items. If you send it 3 items, it creates one loop containing 3 items. If you send it 1000 items, it creates four loops of 250 items. You don't have to write any messy logic or multiple collections ever again!

    ✅ If this helps solve the issue, please mark it as a Verified Answer so others facing a similar issue can find it easily. Thanks!!

  • Suggested answer
    WarrenBelz Profile Picture
    156,732 Most Valuable Professional on at
    I suggest you do one collection - ensure your Data Row Limit  is set to at least 1,000.
    If(
       IsError(
          ClearCollect(
             colItems,
             FirstN(
                ForAll(
                   Gallery2.AllItems,
                   {
                      dataProcessingID: DataProcessingID,
                      productID: ProductID,
                      approverEmail: User().Email,
                      userRemark: TextInput1_1.Text,
                      approvalStatus: "Rejected",
                      pricelistType: "Vendor",
                      approvalTime:
                      Text(
                         Now(),
                         DateTimeFormat.UTC
                      )
                   }
                ),
                1000
             )
          )
       ),
       Notify(
         "Error: Could not create the collection", 
         NotificationType.Error
       )
    );
    Then send it all in four batches like this
    ForAll(
       Sequence(
          RoundUp(
             CountRows(colItems) / 250,
             0
          )
       ),
       SendtoAPI.Run(
          JSON(
             LastN(
                FirstN(
                   colToSend,
                   Min(
                      Value * 250,
                      CountRows(colToSend)
                   )
                ),
                Min(
                   250,
                   CountRows(colToSend) - ((Value - 1) * 250)
                )
             ),
             JSONFormat.IgnoreBinaryData &
             JSONFormat.IgnoreUnsupportedTypes
          )
       )
    )
     
    Please ✅ Does this answer your question 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 answering Yes to Was this reply helpful? or give it a Like ♥
    Visit my blog
    Practical Power Apps    LinkedIn  
  • Suggested answer
    M Bilal Khan Profile Picture
    1,155 on at
    Hi @Joost Cuppes,

    You don't need five separate collections for this. I'd build the payload once and then split it dynamically into batches of 250.

    For example:

    ClearCollect(
        colPayload,
        ForAll(
            Gallery2.AllItems,
            {
                dataProcessingID: DataProcessingID,
                productID: ProductID,
                approverEmail: User().Email,
                userRemark: TextInput1_1.Text,
                approvalStatus: "Rejected",
                pricelistType: "Vendor",
                approvalTime: Text(Now(), DateTimeFormat.UTC)
            }
        )
    );
    
    ForAll(
        Sequence(
            RoundUp(CountRows(colPayload) / 250, 0)
        ),
        With(
            {
                batchStart: ((Value - 1) * 250) + 1
            },
            SendtoAPI.Run(
                JSON(
                    FirstN(
                        LastN(
                            colPayload,
                            CountRows(colPayload) - batchStart + 1
                        ),
                        Min(250, CountRows(colPayload) - batchStart + 1)
                    ),
                    JSONFormat.IgnoreBinaryData &
                    JSONFormat.IgnoreUnsupportedTypes
                )
            )
        )
    );
    

    The nice part is that the number of Flow calls is calculated automatically:

    • 0 records → 0 calls
    • 3 records → 1 call
    • 250 records → 1 call
    • 251 records → 2 calls
    • 500 records → 2 calls
    • 501 records → 3 calls
    • 1000 records → 4 calls

    So you don't need colFirst200ListItem, colSecond200ListItem, etc.

    I'd also consider changing the batch size to 250 consistently since that's the limit you mentioned for the HTTP call. This makes the solution independent of the 1000-record Power BI limit and will continue to work if that limit changes.

    One other improvement: if the API/Flow can accept an array directly rather than requiring a JSON string, I'd pass the collection/table directly where possible. Otherwise, the JSON() approach you're already using is fine.

    The main idea is: one payload + dynamic batching, instead of hard-coding five separate collections.

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 354 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 330

#3
Mohsin Ali Profile Picture

Mohsin Ali 232

Last 30 days Overall leaderboard