How to get Collection Column Names in Power Apps [From 3 Different Datasources]

Do you know how to retrieve all the collection names or headers in Power Apps? Well, in this Power Apps tutorial, We will discuss how to get collection column names in Power Apps, How to get collection column names in Power Apps from three various data sources, etc.

Additionally, we will see how to display collection column names in a Power Apps Gallery control as well as Power Apps Dropdown control.

Get Collection Column Names in Power Apps

Here, I will show you how to get collection names in Power Apps from three different Data sources. Such as:

  1. Power Apps Get Collection Column Names from a Collection
  2. Power Apps Get Collection Column Names from a SharePoint List
  3. Power Apps Get Collection Column Names from a Dataverse Table

Let’s explore each one of these now.

Power Apps Get Collection Column Names from a Collection

In this section, we will see how to get collection column names from a Power Apps Collection.

  • For example, I have a Power Apps Collection named colBlogDetails. This collection has some records including five headers like Blog Title, Blog Website, Publication Date, Assigned to, and Status.
  • You can see the code below and how the collection looks like in Power Apps:
// Create a Collection

ClearCollect(
    colBlogDetails,
    {
        BlogTitle: "Power Apps Collection",
        BlogWebsite: "SPGuides.com",
        PublicationDate: "16/02/2023",
        AssignedTo: "Preeti",
        Status: "Completed"
    },
    {
        BlogTitle: "Power Apps Dropdown",
        BlogWebsite: "EnjoySharePoint.com",
        PublicationDate: "18/02/2023",
        AssignedTo: "Sonam",
        Status: "In Progress"
    },
    {
        BlogTitle: "Create Profile in Salesforce",
        BlogWebsite: "SalesforceFAQs.com",
        PublicationDate: "20/02/2023",
        AssignedTo: "Shivam",
        Status: "Pending"
    },
    {
        BlogTitle: "Python Reverse String",
        BlogWebsite: "Pythonguides.com",
        PublicationDate: "21/02/2023",
        AssignedTo: "Arvind",
        Status: "Not Started"
    },
    {
        BlogTitle: "Oracle Database Data type",
        BlogWebsite: "DatabaseFAQs.com",
        PublicationDate: "22/02/2023",
        AssignedTo: "Saurabh",
        Status: "Not Started"
    }
)

Where,

  1. colBlogDetails = Collection name
  2. Blog Title, Blog Website, Publication Date, Assigned to, and Status = Collection Column names

NOTE:

The above code I have written on the Button’s OnSelect property as per my need. But also you can write either on the Screen’s OnVisible property or App’s OnStart property.
How to get Collection Column Names in Power Apps
How to get Collection Column Names in Power Apps
  • Once we will click on the Button (Create Collection & Get Headers), the collection will create and all the values will store inside the Power Apps Collections. Refer to the screenshot below:
Get Collection Column Names in Power Apps
Get Collection Column Names in Power Apps
  • Now to get all the collection names in Power Apps, we can write the code below on the same Button’s OnSelect property as:
// Get Column Names

Set(
    varCollectionColumnNames,
    Distinct(
        Ungroup(
            MatchAll(
                JSON(
                    colBlogDetails,
                    JSONFormat.IgnoreBinaryData
                ),
                "([^""]+?)""\s*:"
            ).SubMatches,
            "SubMatches"
        ),
        Value
    )
)

Where,

  1. varCollectionColumnNames = Variable Name
  2. colBlogDetails = Collection Name
Power Apps Get Collection Column Names
Power Apps Get Collection Column Names
  • Next, to view all the collection column names, we can insert a Power Apps Gallery control and set its Items property to the code below:
Items = varCollectionColumnNames 

Where,

varCollectionColumnNames = Variable name that you have created to get all the collection column names

PowerApps get collection column names
PowerApps get collection column names

This is how to get collection column names from a Power Apps Collection.

Also Read: How to Detect Text in Dataverse Using AI Builder

Power Apps Get Collection Column Names from a SharePoint List

Here, We will see how to get Power Apps collection column names from a SharePoint list.

  • There is a SharePoint list named Employee Onboarding. This list has various columns with different data types. Such as:
    • ID, Employee Name, Employee Last Name, Employee ID, Department, Location, etc. Also, this SharePoint list includes some of the default columns like Created, Created By, Modified, etc.
Power Apps Get Collection Column Names from a SharePoint List
Power Apps Get Collection Column Names from a SharePoint List
  • After that, I’ll create a Power Apps Collection and put all of these column names in it. Following that, I will get every column name from the particular collection.
  • To collect the SharePoint List columns, apply the code below on Button’s OnSelect property as:
// Collect the table values

ClearCollect(
    colEmpOnboardingDetails,
    'Employee Onboarding'
);

Where,

  1. colEmpOnboardingDetails = Collection Name
  2. ‘Employee Onboarding’ = SharePoint List Name

NOTE:

Verify that the SharePoint List Datasource connector is required before implementing the above code. If not, you can experience certain issues.
Get Power Apps Collection Column Names from a SharePoint List
Get Power Apps Collection Column Names from a SharePoint List
  • Now, using the same Button’s OnSelect property, we can write the following code to retrieve all the collection names in Power Apps:
Set(
    varListColumnNames,
    Distinct(
        Ungroup(
            MatchAll(
                JSON(
                    colEmpOnboardingDetails,
                    JSONFormat.IgnoreBinaryData & JSONFormat.IgnoreUnsupportedTypes
                ),
                "([^""]+?)""\s*:"
            ).SubMatches,
            "SubMatches"
        ),
        Value
    )
)

Where,

  1. varListColumnNames = Variable name
  2. colEmpOnboardingDetails = Collection name that you have created to store all the SharePoint list column names
  3. & JSONFormat.IgnoreUnsupportedTypes = Unsupported data types are accepted, but they won’t be included in the final result.
Get Collection Column Names in PowerApps
Get Collection Column Names in PowerApps

IMPORTANT NOTE:

If we will not use this & operator and Power Apps JSONFormat.IgnoreUnsupportedTypes function, then we will get an attachment error that can not not serialized with Power Apps JSON Format.

You can refer this article for more details: The JSON function cannot serialize tables / objects with a nested property called ‘{Attachments}’ of type ‘Table(Attachment)’ Power Apps
  • Next, Click on the button (Tap to get SP List Columns) to create the collection and get SharePoint list columns.
  • Insert a Power Apps Dropdown control and set its Items property to the following code to display all the SharePoint List column names:
varListColumnNames

Where,

varListColumnNames = Created Variable name

How to retrieve collection column names in Power Apps
How to retrieve collection column names in Power Apps
  • So the result will appear in the Power Apps dropdown control as shown below.
How to get Collection Column Names in PowerApps
How to get Collection Column Names in PowerApps

This is how to get Power Apps collection column names from a SharePoint list.

Check Out: How to Update a Row in Dataverse Using Power Automate

Power Apps Get Collection Column Names from a Dataverse Table

Next comes how we can get Power Apps collection column names from a Dataverse table.

  • There is a Dataverse table named Car Booking Details. This table has various columns with different data types. Such as:
    • Car Name, Booking Date, Buyer Name, Buyer Contact Number, etc. Also, this dataverse table includes some of the default columns like Created On, Modified On, Version Number, etc.
Power Apps Get Collection Column Names from a Dataverse Table
Power Apps Get Collection Column Names from a Dataverse Table
  • After that, I’ll add all of these table column names to a Power Apps Collection that I’ll create. I will then obtain the names of each column in the specific collection.
  • Use the following code to collect the Dataverse table columns on the Button’s OnSelect property:
// Collect the table values

ClearCollect(
    colCarBookingInfo,
    'Car Booking Details'
);

Where,

  1. colCarBookingInfo = Collection Name
  2. Car Booking Details‘ = Dataverse Table Name

NOTE:

Verify that the Dataverse connector is required before implementing the above code. If not, you can experience certain issues.
Get collection headers in Power Apps
Get collection headers in Power Apps
  • Now, using the same Button’s OnSelect property, we can write the following code to retrieve all the collection names in Power Apps:
// Get the column headers

Set(
    varColumnNames,
    Distinct(
        Ungroup(
            MatchAll(
                JSON(
                    colCarBookingInfo,
                    JSONFormat.IgnoreBinaryData & JSONFormat.IgnoreUnsupportedTypes
                ),
                "([^""]+?)""\s*:"
            ).SubMatches,
            "SubMatches"
        ),
        Value
    )
)

Where,

  1. varColumnNames = Variable name
  2. colCarBookingInfo = Collection name that you have created to store all the Dataverse table column names
  3. & JSONFormat.IgnoreUnsupportedTypes = Unsupported data types are accepted, but they won’t be included in the final result.
Get Collection Column Names Power Apps
Get Collection Column Names Power Apps

IMPORTANT NOTE:

If we will not use this & operator and Power Apps JSONFormat.IgnoreUnsupportedTypes function, then we will get an polymorphic error that can not not serialized with Power Apps JSON Format.
You can refer this article for more details: The JSON function cannot serialize tables / objects with a nested property called ‘_ownerid_value’ of type ‘Polymorphic’ Power Apps
  • Next, Click on the button (Tap to get Dataverse Table Columns) to create the collection and get all the Dataverse table columns.
  • Add a Power Apps Dropdown control and set its Items property to the following code to display all the Dataverse table column names:
varColumnNames

Where,

varColumnNames = Created Variable name

Retrieve collection column names in PowerApps
Retrieve collection column names in PowerApps
  • As a result, the outcome will show up in the Power Apps dropdown control as displayed below. Here, the Dataverse table column names (those are custom columns) will appear with the internal name that includes a prefix like crf9a_bookingdate.
Retrieve collection column names in Power Apps
Retrieve collection column names in Power Apps

This is how to get Power Apps collection column names from a Dataverse table.

Furthermore, you may like some more below Power Apps & Dataverse tutorials:

In this Power Apps tutorial, We discussed how to get collection column names in Power Apps, How to get collection column names in Power Apps from three various data sources, etc.

Additionally, we saw how to display collection column names in a Power Apps Gallery control as well as Power Apps Dropdown control.

>