Skip to main content

How to Add a Column to a Table in Power Apps with AddColumns

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

Sometimes a gallery needs a value that isn't a column of its data: a status worked out from another list, a total, a label. AddColumns adds it as a new column, calculated once for each row, and the gallery's controls read it like any other column.

Syntax​

Syntax
AddColumns( Table, ColumnName1, Formula1 [, ColumnName2, Formula2, ... ] )

For each record of Table, the formula is worked out and stored in the new column. The original table isn't changed; AddColumns returns a new one (AddColumns, DropColumns, RenameColumns, and ShowColumns).

Column names are written without quotes. Microsoft notes that apps made before version 3.24042 used quoted names, and were updated automatically.

Prerequisites​

  • A table, such as a gallery's Items. The example is the Career Development Plan app's My Plan screen, where a gallery lists competencies and needs each one's status from a second list of responses.

Example: A Status Column​

Each competency's status comes from the person's response to it, if there is one. AddColumns adds a StatusText column to the competencies:

galMyPlanMPS → Items
AddColumns(
locMyPlan As planItem,
StatusText,
Switch(
LookUp(
locMyResponses,
RoleCompetencyId = planItem.ID && Level = planItem.Level.Value
).Status.Value,
StatusPending, "Waiting for review",
StatusApproved, "Approved",
StatusDeclined, "Declined",
"Not started"
)
)

For each competency, LookUp finds the matching response, and Switch turns its status into text. As planItem names the competency, so the formula can tell its Level apart from the response's Level (How to Use the As Operator in Power Apps).

While the screen was being designed, the same formula ran over the whole RoleCompetencies list. With no responses yet, every row read Not started:

The expanded formula bar with AddColumns(RoleCompetencies As planItem, StatusText, Switch(LookUp(locMyResponses, RoleCompetencyId = planItem.ID && Level = planItem.Level.Value)...)), Data type Table, and gallery rows with a Not started badge under each competency and level

In the gallery, the new column is read like the others:

bdgStatusMPS → Content
ThisItem.StatusText

Working the status out once per row, in Items, means the badge's Content, its color and the row's accessible label all use the same value.

Delegation​

Microsoft notes that the arguments of AddColumns can be delegated, but its result is subject to the app's data row limit (500 by default). If the table comes straight from a large SharePoint list, only the first rows get the new column. In the example, the table is a variable that already holds just one person's plan. See What Is Delegation in Power Apps?

Common Mistakes​

MistakeWhat happensDo this instead
Expecting the data source to get a new columnNothing changes in SharePointAddColumns only shapes the copy your formula uses
Using AddColumns on a big list directlyOnly the first rows (data row limit) are processedFilter first, or load the rows you need
Working the same value out in several controlsThe formulas can drift apartAdd it once as a column

Troubleshooting​

SymptomLikely causeFix
The new column isn't suggested after ThisItem.Items doesn't use AddColumns, or has an errorCheck the gallery's Items
The calculated value is wrong in some rowsThe formula reads the wrong record's columnName the record with As

FAQ​

Does AddColumns change my SharePoint list?​

No. It returns a new table. To change a list's columns, change the list in SharePoint.

Can I add more than one column?​

Yes: add more name and formula pairs.

Conclusion​

AddColumns(table, Name, formula) adds a calculated column to a copy of the table. Use it in a gallery's Items to work a value out once per row, and name the record with As when the formula looks into another table.

Additional Resources​

Stay Updated

Subscribe to our newsletter for the latest tutorials, tech insights, and developer news.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.