Power Apps Repeating Tables: A Developer's Guide
Many business applications require users to enter multiple rows of related information within a single form. Examples include expense reports, purchase requests, project tasks, employee certifications, and invoice line items. Unlike traditional web applications, Power Apps does not provide a built-in repeating table control. However, by using Galleries and Collections, developers can create dynamic repeating tables that allow users to add, edit, and remove multiple records efficiently. Repeating tables are one of the most commonly used design patterns in Canvas Apps because they provide flexibility while maintaining a user-friendly experience.What is a Repeating Table?
A repeating table is a data-entry structure where users can dynamically add multiple rows of information. Instead of creating fixed fields, users can continuously add rows as needed.
Example:
| Item | Quantity | Price |
|---|---|---|
| Laptop | 2 | $1200 |
| Monitor | 3 | $300 |
| Mouse | 5 | $25 |
Common Business Scenarios
- Purchase Requests: Add multiple products in a single request.
- Expense Claims: Enter multiple expense items.
- Project Management: Add multiple tasks under a project.
- Employee Certifications: Store multiple certifications for one employee.
- Invoice Entry: Create multiple invoice line items.
Why Use Galleries?
In Power Apps, Galleries act as repeating containers. Benefits include:
- Dynamic row creation
- Editable records
- Flexible layouts
- Better user experience
- Integration with Dataverse and SharePoint
Each gallery item represents one row in the repeating table.
Step-by-Step Implementation
Step 1: Create a Collection
On screen load, use the OnVisible property to initialize a collection. This creates the first row in the repeating table.
ClearCollect( colLineItems, { ItemName: "", Quantity: 0, Price: 0 } )
Step 2: Insert a Gallery
Add a Vertical Gallery to your screen. Set its Items property to your collection (e.g., colLineItems). The gallery will now display the records from your collection.
Step 3: Add Input Controls
Inside the gallery template, add TextInput controls for each field (e.g., ItemName, Quantity, Price). Set the Default property of each input control to the corresponding field name from the collection (e.g., ThisItem.ItemName). This makes each row editable.
Step 4: Add New Rows
Insert a button (e.g., "Add Row"). Set its OnSelect property to collect a new blank record into your collection:
Collect( colLineItems, { ItemName: "", Quantity: 0, Price: 0 } )
Users can now add unlimited rows dynamically.
Step 5: Remove Rows
Add a delete icon inside the gallery template. Set its OnSelect property to remove the current item from the collection:
Remove( colLineItems, ThisItem )
Users can delete rows instantly.
Step 6: Calculate Totals
Add a label to display the total. Use the Sum function to calculate the total based on your fields:
Sum( colLineItems, Quantity * Price )
This provides real-time calculations.
Step 7: Save Data to SharePoint
To save the collection data to a SharePoint list, use the ForAll and Patch functions. This will create a new parent record for each row in the collection.
ForAll( colLineItems, Patch( PurchaseRequests, Defaults(PurchaseRequests), { ItemName: ItemName, Quantity: Quantity, Price: Price } ) )
All rows are stored automatically.
Step 8: Save Data to Dataverse
Similarly, you can save data to Dataverse. This typically involves creating child records linked to a parent record.
ForAll( colLineItems, Patch( 'OrderDetails', Defaults('OrderDetails'), { Product: ItemName, Quantity: Quantity, Price: Price } ) )
This creates child records in Dataverse.
Example Architecture
The typical architecture for a repeating table implementation in Power Apps is:
- User interacts with the form.
- Data is managed in a Gallery.
- The Gallery displays records from a Collection.
- Users can Add/Edit/Delete Rows within the Gallery.
- When submitting, the Collection data is saved to a Data Source (SharePoint/Dataverse).
Real-World Example: Purchase Order Application
Imagine a user entering items for a purchase order:
- User enters: Laptop, 2, $1200; Monitor, 3, $300; Mouse, 5, $25.
- User clicks: Submit.
- Power Apps: Loops through the collection, creates records in the data source, and stores line items.
- Result: A complete purchase order with multiple products is generated.
Best Practices
- Use Collections: For flexibility in temporary storage.
- Use Galleries: Avoid multiple static controls for repeating data.
- Validate Data: Ensure required fields are completed.
- Calculate Totals Dynamically: Use
Sum()and formulas for real-time updates. - Optimize Performance: Avoid unnecessary collection refreshes.
- Store Parent-Child Relationships: Link line items to parent records appropriately.
Benefits
- Better User Experience: Users can add unlimited rows easily.
- Reduced Development Time: A single gallery handles all record management.
- Scalable Design: Works for both small and large datasets.
- Flexible Data Entry: Supports complex business scenarios.
- Seamless Integration: Works with Dataverse, SharePoint, SQL, and APIs.
Common Use Cases
- Purchase Orders: Multiple products per request.
- Expense Reports: Multiple expenses per claim.
- Project Tasks: Multiple tasks per project.
- Timesheets: Multiple work entries.
- Invoices: Multiple line items.
Conclusion
Repeating tables are one of the most powerful UI patterns in Power Apps. By combining Galleries, Collections, and data sources such as SharePoint or Dataverse, organizations can create dynamic forms that allow users to add, edit, and remove multiple records seamlessly. This approach provides flexibility, scalability, and a modern user experience while supporting complex business requirements.