Latest Posts

PowerApps How to Add Column in table or collection


The AddColumns function in Power Apps allows you to add new columns to a table, transforming and enriching your data by calculating new values based on existing data. This function can be particularly useful for creating derived values, performing calculations, or enhancing data for display purposes.

PowerApps – AddColumns() function Syntax

AddColumns(Table, ColumnName, Formula)

  • Table: The input table to which you want to add columns.
  • ColumnName: The name of the new column you want to add.
  • Formula: The formula used to calculate the values for the new column.

PowerApps – Add a Calculated Column in Collection

Suppose you have a collection of products with their names and prices, and you want to add a column to calculate the discounted price.

  1. Set up your collection:

ClearCollect(Products,

    Table(

        {ProductID: 1, ProductName: "Laptop", Price: 1000},

        {ProductID: 2, ProductName: "Tablet", Price: 500},

        {ProductID: 3, ProductName: "Monitor", Price: 300}

    )

);

  1. Add a column for the discounted price:

ClearCollect(DiscountedProducts,

    AddColumns(Products, "DiscountedPrice", Price * 0.9)

);

This will create a new collection, DiscountedProducts, with a DiscountedPrice column that is 90% of the original price.

PowerApps – Add a Column with Conditional Logic in collection

You can use AddColumns to create new columns based on conditional logic. For instance, adding a column to categorize products as "Expensive" or "Affordable" based on their price.

  1. Set up your collection:

ClearCollect(Products,

    Table(

        {ProductID: 1, ProductName: "Laptop", Price: 1000},

        {ProductID: 2, ProductName: "Tablet", Price: 500},

        {ProductID: 3, ProductName: "Monitor", Price: 300}

    )

);

  1. Add a column for categorizing products:

ClearCollect(CategorizedProducts,

    AddColumns(Products, "Category", If(Price > 600, "Expensive", "Affordable"))

);

This will create a new collection, CategorizedProducts, with a Category column indicating whether each product is "Expensive" or "Affordable".

PowerApps – Add Multiple Columns in a collection

You can add multiple columns in a single call to AddColumns by chaining the function.

  1. Set up your collection:

ClearCollect(Products,

    Table(

        {ProductID: 1, ProductName: "Laptop", Price: 1000},

        {ProductID: 2, ProductName: "Tablet", Price: 500},

        {ProductID: 3, ProductName: "Monitor", Price: 300}

    )

);

 

  1. Add multiple columns:

ClearCollect(EnhancedProducts,

    AddColumns(

        AddColumns(Products, "DiscountedPrice", Price * 0.9),

        "Category", If(Price > 600, "Expensive", "Affordable")

    )

);

This will create a new collection, EnhancedProducts, with both DiscountedPrice and Category columns.

PowerApps – Use AddColumns with Data from SharePoint in collection

You can use AddColumns with data from a data source like SharePoint, SQL, or Excel.

  1. Assume you have a SharePoint list named "Orders" with columns "OrderID", "Product", "Quantity", and "UnitPrice".
  2. Add a column to calculate the total price for each order:

ClearCollect(EnhancedOrders,

    AddColumns(Orders, "TotalPrice", Quantity * UnitPrice)

);

This will create a new collection, EnhancedOrders, with a TotalPrice column.


We value your Feedback:

Page URL:

Name:

Email:


Suggestion:

© 2024 Code SharePoint