Enrich Your Galleries with AddColumns in Power Apps

The AddColumns function in Power Apps is a versatile tool to manipulate data tables and present new data in galleries.

It allows you to enrich your data tables by dynamically adding new columns without altering the original data source.

This makes it perfect for scenarios where you need calculated fields, derived values, or data from related tables—all within your app.

What is AddColumns?

The AddColumns function creates a new table by adding one or more columns to an existing table.

Syntax:

Code

AddColumns( Table, ColumnName, Formula [, ColumnName2, Formula2, ...] )
  • Table → The source table (e.g., SharePoint list, collection).
  • ColumnName → The name of the new column.
  • Formula → The expression that defines the column’s values.

The original table remains unchanged; the new column exists only in the context of your app.

Example 1: Adding a Calculated Column (Tax)

Imagine you have a Products SharePoint list with the following fields:

  • Product
  • Price
  • Quantity

You want to display a Tax column in a gallery, calculated as 15% of the price.

Formula:

powerfx

AddColumns( Products, "Tax", Price * 0.15 )
  • The gallery now shows Product, Price, and the new Tax column.
  • Importantly, this column exists only in Power Apps—it does not modify the SharePoint list.

Example 2: Using Collections with AddColumns

Instead of applying AddColumns directly in the gallery, you can create a collection that includes the new column.

OnStart property of the app:

powerfx

ClearCollect(
    ProductsWithTax,
    AddColumns( Products, "Tax", Price * 0.15 )
)
  • This stores a new table in memory called ProductsWithTax.
  • You can then bind your gallery to this collection.
  • When the app starts, the collection is populated automatically.

Example 3: Adding Data from Related Tables

Consider an Orders SharePoint list with:

  • Title
  • CustomerID
  • Quantity
  • Price

And a Customers list with:

  • ID
  • Name

The Orders list only stores CustomerID, but you want to display the Customer Name in your gallery.

Formula:

powerfx

AddColumns(
    Orders As O,
    "CustomerName",
    LookUp( Customers, ID = O.CustomerID, Name )
)
  • Here, LookUp retrieves the customer’s name from the Customers list.
  • The gallery now shows Title, CustomerID, Quantity, Price, and the new CustomerName column.

Example 4: Adding Multiple Columns

You can add more than one column at a time. For instance, to calculate the Order Total:

Formula:

powerfx

AddColumns(
    Orders As O,
    "CustomerName",
    LookUp( Customers, ID = O.CustomerID, Name ),
    "OrderTotal",
    O.Price * O.Quantity
)
  • CustomerName is fetched from the Customers list.
  • OrderTotal is calculated by multiplying price and quantity.

Key Benefits of AddColumns

  • Self-contained: Does not alter the original data source.
  • Flexible: Works with SharePoint lists, collections, or other tables.
  • Dynamic: Columns are created at runtime, tailored to your app’s needs.
  • Powerful: Can combine calculations, lookups, and multiple columns in one function.

Conclusion

The AddColumns function is essential for building dynamic, data-driven Power Apps.

Whether you’re calculating taxes, enriching orders with customer names, or creating collections with derived values, AddColumns gives you the flexibility to shape your data exactly how your app requires—without touching the underlying source.

Comments

Leave a Comment

Your email address will not be published. Required fields are marked *