Power Apps Galleries and Forms

Earn 25 points (50 with Pro) in two steps

  1. ① Read through the lesson — each section gets a ✓ as you scroll through it.
  2. ② When every section has a ✓, tap Complete lesson.

0 of 8 read · keep scrolling

✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro

Mastering Power Apps: Galleries and Forms

Introduction: The Foundation of Data Interaction

If you have spent any time working within the Microsoft Power Platform, you have undoubtedly encountered Galleries and Forms. These two controls are the absolute bedrock of almost every canvas application built today. While a Power App might look like a collection of buttons, icons, and labels, the real value of the application lies in how it surfaces, organizes, and modifies data. Galleries allow users to view lists of information, while Forms provide the structure necessary to create, edit, and save that data back to your data source.

Understanding how to manipulate these controls effectively is what separates a basic, static application from a professional-grade tool that solves complex business problems. When you master Galleries, you master the art of data presentation; when you master Forms, you master the art of data integrity. In this lesson, we will peel back the layers of these controls, looking not just at how to drag and drop them onto a screen, but how to optimize their performance, handle complex data scenarios, and ensure that your users have a responsive and intuitive experience.


Not read yet

Part 1: The Power of Galleries

A Gallery is essentially a container for a repeating set of data. Think of it as a smart list. You provide a data source—such as a SharePoint list, a Dataverse table, or an Excel file—and the Gallery automatically generates a template row that repeats for every item in that source. However, a Gallery is far more than just a list of text; it is a highly customizable canvas that can hold images, icons, buttons, and even nested galleries.

Anatomy of a Gallery

When you insert a Gallery, you are presented with several layouts, such as "Vertical," "Horizontal," or "Blank." Regardless of the choice, the internal structure remains consistent. The Gallery control has an Items property, which dictates what data is displayed. Within the gallery, there is a "Template" area. Any control you place inside this template is replicated for every record returned by the Items property.

Callout: Gallery vs. Data Table Many beginners are tempted to use the "Data Table" control because it looks like a spreadsheet. However, the Data Table is limited in terms of styling and interactivity. Galleries are far superior because they allow you to place buttons, toggle switches, and complex formulas inside each row. Use Data Tables only for quick, read-only internal administrative views; use Galleries for everything else.

Practical Data Filtering and Sorting

One of the most common requirements in a business application is the ability to filter data. Instead of showing a user 5,000 records, you should present them with a manageable subset. The Items property of your gallery is where you define this logic.

To filter a list based on a text input, you would use the Filter function combined with the Search function. Consider this example where you have a list of employees:

Filter(
    Employees, 
    Department = Dropdown_Dept.Selected.Value,
    StartsWith(FullName, txt_Search.Text)
)

In this code, the Filter function scans the Employees data source. It first checks if the Department column matches the selection from a dropdown control. Then, it uses the StartsWith function to ensure that the FullName begins with whatever the user has typed into the search box. This keeps the gallery responsive and relevant to the user's current task.

Improving Gallery Performance

Performance is a significant concern when dealing with large datasets. If your Items property is too complex, the application will feel sluggish. Here are a few best practices to keep your galleries snappy:

  • Delegation: Always ensure your Items formula is "delegable." This means the filtering is performed on the server side (by SharePoint or Dataverse) rather than on the user's device. If you use functions that are not delegable, like Search on certain data sources, Power Apps will only retrieve the first 500 or 2,000 records, which can lead to data loss in your view.
  • Limit Columns: If you are using a large Dataverse table, only fetch the columns you actually need. While Power Apps often handles this automatically, being mindful of your data retrieval scope is a good habit.
  • Virtualization: Galleries are automatically virtualized, meaning they only render the items visible on the screen. Do not try to force a gallery to render 1,000 items at once; instead, use pagination or search filters to keep the view focused.

Not read yet

Part 2: Mastering Forms for Data Input

While Galleries are for viewing, Forms are for interacting. An "Edit Form" or "Display Form" is a container that binds directly to a record in your data source. When you connect a form to a SharePoint list or Dataverse table, Power Apps automatically generates the input fields based on the schema of that list.

Understanding Form Modes

A Form control has a property called Mode. This property is critical to how the form behaves:

  1. FormMode.Edit: Used to modify an existing record. You must provide the form with a specific record via the Item property (e.g., Gallery1.Selected).
  2. FormMode.New: Used to create a brand-new record. The Item property should typically be set to Defaults(YourDataSource).
  3. FormMode.View: Used to display a record without allowing the user to make changes.

Note: Always use the SubmitForm function to save data from a form. Some beginners try to patch fields individually to a data source, but using SubmitForm is the standard way to handle form validation, error messages, and data submission in one clean step.

Customizing Form Cards

Every field in a form is wrapped in a "Data Card." These cards are essentially containers that hold the label, the input control (like a text box or dropdown), and an error message control. You can unlock these cards to change their appearance, add conditional formatting, or move them around.

If you need to change the visibility of a field based on another field, you can select the Data Card and set its Visible property:

// Set the Visible property of a "Comments" card to true only if "Status" is "Rejected"
DataCard_Comments.Visible = Dropdown_Status.Selected.Value = "Rejected"

This level of dynamic control is what makes Power Apps so powerful. You aren't just creating a static form; you are creating a logical interface that adapts to the user's input in real-time.

Handling Data Submission Errors

When using SubmitForm, it is important to provide feedback to the user. You should use the OnSuccess and OnFailure properties of the form to trigger notifications.

  • OnSuccess: Use Notify("Data saved successfully!", NotificationType.Success) to reassure the user that their work is safe.
  • OnFailure: Use Notify("There was an error saving your data.", NotificationType.Error) to alert them if something goes wrong, such as a network timeout or a validation issue.

Not read yet

Part 3: Advanced Techniques and Integration

Once you have mastered the basics of Galleries and Forms, you can start combining them to create sophisticated workflows. A common pattern is the "Master-Detail" view, where a Gallery on the left shows a list of items, and a Form on the right shows the details of the item selected in the gallery.

The Master-Detail Pattern

To implement this, set the Item property of your Form to Gallery1.Selected. When the user clicks an item in the gallery, the form automatically updates to show the information for that specific record.

Tip: If you want to allow the user to switch between "Edit" and "View" modes for the same record, create a variable (e.g., varFormMode) and toggle it using a button. Set the Mode property of your form to this variable. This prevents the need for two separate screens.

Working with Complex Data Types

Sometimes, your data source will contain complex types like Choice columns, Lookups, or Attachments.

  • Choices: Power Apps handles these well with the ComboBox control. Ensure the Items property of the combo box is set to Choices(DataSourceName.ColumnName).
  • Lookups: If you are linking two tables, the DefaultSelectedItems property of the combo box is where you define the link. Always use the LookUp function to ensure the correct record is identified.
  • Attachments: The "Attachment" control in Power Apps is a specialized control that only works inside a Form. Do not try to move it outside the form or copy-paste it into a gallery; it requires the context of the parent form to manage the file upload process correctly.

Not read yet

Part 4: Common Pitfalls and How to Avoid Them

Even experienced developers can fall into traps when working with these controls. Here are the most frequent mistakes I see in production environments.

1. Hard-Coding Values

Avoid hard-coding values like "Pending" or "Approved" directly into formulas. If the business changes these terms later, you will have to hunt through every formula in your app to update them. Instead, use a "Configuration" list or a local collection to store these values, and reference that variable or list.

2. Ignoring Delegation Warnings

Power Apps will show a yellow warning triangle if your formula is not delegable. Never ignore these. If your app works perfectly with 50 items but breaks when you hit 501 items, it is because of a delegation error. Always check your formulas against the documentation for your specific data source (SharePoint, SQL, or Dataverse).

3. Over-Complicating the Gallery Template

Keep the Gallery template as light as possible. If you have 50 items in a gallery, and each item has 10 complex nested controls, the app will consume a massive amount of memory. Use icons instead of images where possible, and avoid complex calculations inside the gallery template controls.

4. Forgetting to Reset Forms

When a user finishes editing an item, they might close the form. If they open it again, the old data might still be there. Always use the ResetForm function when navigating away or when a user clicks "Cancel."

// Example of a Cancel button formula
ResetForm(Form_Main);
Navigate(Screen_Dashboard);

Not read yet

Part 5: Comparison of Controls

To help you decide which control to use for specific scenarios, refer to the table below.

Feature Gallery Form Data Table
Primary Use Browsing/Selecting Editing/Creating Read-only lists
Customization Very High Medium Low
Data Binding Items (Collection) Item (Single record) Items (Collection)
User Input Possible (via controls) Native (Form controls) None
Best For Dashboards, Search results Data entry, Profiles Quick reporting

Part 6: Best Practices for Production Apps

When building for an organization, consistency is key. Your users should have a predictable experience regardless of which screen they are on.

  • Consistent Naming: Use a naming convention for your controls. For example, gal_Employees, frm_EmployeeDetails, txt_Search, and btn_Submit. This makes debugging much easier when you are looking at a list of hundreds of controls.
  • Validation: Use the Visible property of icons to show validation warnings. For example, if a mandatory field is empty, show a red exclamation icon next to the field. Use the Valid property of the form to enable or disable the "Submit" button.
  • The "Loading" State: For complex forms, use a variable to show a loading spinner while the SubmitForm function is running. This prevents users from clicking the "Submit" button multiple times, which can create duplicate records.

Callout: The Power of 'Patch' While SubmitForm is the standard for forms, the Patch function is the standard for "on-the-fly" updates. If you want to update a single status field without showing a full form, use Patch(DataSource, Record, {Status: "Complete"}). This is faster and cleaner for simple updates.


Not read yet

Part 7: Step-by-Step: Creating a Basic Edit Flow

To solidify these concepts, let’s walk through the process of creating a standard Edit flow.

Step 1: Setup the Gallery

  1. Insert a Gallery control onto your screen.
  2. Connect it to your data source (e.g., Projects).
  3. In the Gallery, add labels for Title, Status, and DueDate.

Step 2: Setup the Form

  1. Add an "Edit Form" control to the same screen.
  2. Connect it to the same Projects data source.
  3. Set the Item property of the form to Gallery1.Selected.

Step 3: Link the Selection

  1. When a user taps an item in the gallery, the OnSelect property is usually set to Select(Parent). This is fine.
  2. Ensure the form fields are visible. If they are hidden, select the form and use the "Edit Fields" pane to add the columns you need.

Step 4: Add the Save Button

  1. Add a button outside the form.
  2. Set the OnSelect property to SubmitForm(Form1).
  3. Set the DisplayMode of the button to If(Form1.Valid, DisplayMode.Edit, DisplayMode.Disabled). This ensures the user cannot save if the form has errors.

Step 5: Feedback Loop

  1. Set the OnSuccess property of the form to: Notify("Saved!", NotificationType.Success); Navigate(Screen_Dashboard).
  2. Set the OnFailure property to: Notify("Error!", NotificationType.Error).

This simple flow covers 90% of the data entry requirements in most business applications. By following this pattern, you ensure that your app is reliable, user-friendly, and easy to maintain.


Not read yet

Summary and Key Takeaways

We have covered a significant amount of ground regarding the two most critical components of Power Apps. By understanding how to manipulate Galleries for display and Forms for input, you have the building blocks to create nearly any business application.

Key Takeaways:

  1. Galleries are for Lists: Always prefer Galleries over Data Tables for their superior customization and control. Use them to display data, facilitate searching, and allow for item selection.
  2. Forms are for Integrity: Use Forms to ensure that data entry follows the rules of your data source. Leverage SubmitForm to handle the heavy lifting of data validation and submission.
  3. Master the Item Property: The magic of a Master-Detail view is simply binding the Form’s Item property to the Gallery’s Selected property. This creates a powerful, reactive interface.
  4. Prioritize Delegation: Always be aware of delegation warnings. If your app needs to work with large datasets, your formulas must be delegable to keep the app performing well and the data accurate.
  5. Use Feedback Loops: Never leave the user guessing. Always use Notify and clear UI indicators (like spinners or validation icons) to communicate the state of the application.
  6. Keep it Simple: Avoid over-engineering your gallery templates or form layouts. A clean, simple interface is almost always easier to maintain and faster for the user to navigate.
  7. Consistency Matters: Adopt a naming convention for your controls early. When your app grows to include dozens of screens, you will be grateful for a structured approach to naming your galleries, forms, and data cards.

By applying these principles, you will move from simply "making things work" to building professional-grade applications that are robust, scalable, and intuitive for your end users. Remember that Power Apps is an iterative process; start with the basic functionality, test it, and then refine your UI and logic as you learn more about your users' needs.

Not read yet

Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.