The ShowColumns function creates a new table including all the columns that you specify and exclude all other columns. It does not modify the original table.
Syntax:
ShowColumns( Table, ColumnName1 [, ColumnName2, ... ] )
- Table – Required. This is the source table or data source from which you want to select specific columns.
- ColumnName(s) – Required. Name(s) of the column(s) you want to include in the new table. You must specify column name with double quotes included.
Let’s look at an example of using ShowColumns function in Power Apps.
For this example, we are using is a data source as SharePoint list named EmpInfo.
You can see in below screenshot. On Button click we are removing an existing data and storing a new data into collection named Cl_EmpInfo from souce table EmpInfo.
ClearCollect( Cl_EmpInfo, EmpInfo );
Let’s take a look at the data stored in collection. Go to Variables tab then expand the Collections and you can see collection named Cl_EmpInfo is created.
Once, you click on View Table you can see the data stored in collection. It contains all the columns from source table. To see all the columns just scroll to the right.
In case, if you are using SharePoint List as a data source you may see few more extra columns in data source such as Modified, Created, FullPath, Attachements, IsFolder and so on..
Storing all the columns from data source to the collection is not a good idea as it will impact app performance.
So, whenever you need to store source data to collection, you should always store specific columns that you need for further use. You can select specific columns using ShowColumns function.
Select specific columns from source table using ShowColumns function
Let’s create a collection and store specific columns into collection.
OnSelect property of Button write a below formula. It creates a collection named Cl_EmpInfo which contains Name, City and Country details only from EmpInfo table.
ClearCollect( Cl_EmpInfo, ShowColumns( EmpInfo, "Name", "City", "Country" ) );
Let’s click on button to store data into collection.
Now, check the collection. Go to Variables tab then expand the Collections and you can see collection named Cl_EmpInfo is created.
Now, click on View Table to see the data stored in collection.
And you can see, it contains the data only for specific columns such as Name, City and Country.
This is the benefit of using ShowColumns as it includes only those column that we want to add in table.
As collection is an in-memory database-like table which stores the data in-memory, which may impact app performance when working on large datasets.
So, rather than taking all the columns from source table you can select specific columns as per your need and store them in collection. In this way, you can significantly improve app performance as well as you can enhance data privacy and security. As you can exclude sensitive or confidential information from table.
Also Read..
Text function to format date/time or numbers to text string