cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BHerz
Helper I
Helper I

Format values from Collection Table displayed in Data Table

I have a Collection which contsins a table

The content of the Collection is diplayed in a PowerApp Data Table Control

The format of the data does not display any formatting such as $ or , normally available in other controls using the Text( XXX,"$##,#") Formatting.

See Screen shots below

 

How do I format the content of a DataTable?Formatting PowerApp Data Table content.jpg

 

1 ACCEPTED SOLUTION

Accepted Solutions

When you use the AddColumns function, you don't modify the collection / data source in the first parameter of the function. In your example, this expression in the button's OnSelect:

AddColumns(Destinations,"State",State1)

Does not modify the Destinations collection. It returns a new collection, with an additional column, and since that collection is not being used (e.g., assigned to a control Items property, collected to another collection, etc), then its value is discarded.

 

The AddColumns is used mostly to create a "calculated" column, whose value is based on the values of the other columns. Going back to the expression above, if the collection Destinations had, say, 10 items, then the collection returned would have a column "State" with the value of the text input for all of the items, which is probably not what you intended.

 

Take a look at the updated app at https://1drv.ms/u/s!AonXZuy7S5iZiZEQB4UMKb7cn7FIEQ. It shows an example of the AddColumns taking the value of an existing column (e.g., CityState) and creating a new column based on that (e.g., extracting the city part). Or in the original example of this thread - taking a column with a numeric value, and creating a new column that formats it as we want.

 

Hope this helps!

View solution in original post

11 REPLIES 11
CarlosFigueira
Power Apps
Power Apps

You cannot format the data directly on the data table, but you can change the data that is passed to the data table, by using the AddColumns function to add new "virtual" columns with the formatted values in the Items property of the data table control:

AddColumns(
    collectionName,
    "SelectedRSFAvailable2", Text(SelectedRSFAvailable, "$##,#"),
    "TotalRSFAvailable2", Text(TotalRSFAvailable, "$##,#"))

Then in the data table you choose the formatted columns to be displayed.

Hi Carlos,

This make perfect sense thanks for the information.

But...

I assume after running the "AddColumns"  action the Collection should show the the added columns.

I have not been able to make it work.

Below is a step-by-step series of screenshots

Your help is greatly appreciated.

Are you aware if any of the PowerApp samples that use the AddCollumns function I could study?

Bruce

 Format Error Message3.jpg

 

 

 

The data source passed to the data table now has 4 columns (SelectedRSFAvailable, SelectedRSFAvailable2, TotalRSFAvailable, TotalRSFAvailable2) - but the first two columns are still selected. If you select the data table and go to the Data pane, you should see the new columns:

ForumPost001.PNG

There you can unselect the existing ones and select the new ones.

 

Hi Carlos,

Thanks for the details, I am obviously missing a key concept.

When I attempt to "addcolumns” my data source does not reflect the added columns as shown in your example.

I will start with a fresh app and try a simple example and let you know what I find.Format Error Message4.jpg

Carlos,

Thanks for the continued Support!

I have created a simple app  to demonstrate the issue I am having.

The demo has a collection named "Desinations" and two buttons.

The first step is to ClearCollect the City name.

The second step button is to AddColumn "State" to the Desination Collection.

When run, the AddColumn "State" is not added to the destination Collection

The app has been exported and availabe at the URL provided.

if you can not access the Sample App I can send screen shots.

Bruce

https://app.box.com/s/znzbni9x6gjc1038k4q402w0ytqjzdik

 

 

It turns out that you're hitting a bug that I wasn't since I was testing with a local collection instead of a connected data source. When I tried the same scenario with such data source (in my case a SQL table), I saw the same issue that you did.

 

There is still a workaround, which is to cache the data locally, and the AddColumns call should work. I wrote a post at https://blogs.msdn.microsoft.com/carlosfigueira/2017/09/01/formatting-fields-in-data-tables/ that shows what needs to be done. Hopefully this will help unblock you!

 

Thanks!

Hi Carlos,

The link to the example app I sent last week is using a "local data collection" as the blog article suggests.

But, sill can not see the Added columns even using a simplified version without formatting.

AddColumns(Destinations,"State",State1)

 

Here is a link to an "Import Package" of a simple example app which perhaps more clearly demononstrate the issue.

https://app.box.com/shared/static/ke08bqvsk43ocyhl2u9vq2dmgyf91za3.zip

 

Thanks

Bruce

 

When you use the AddColumns function, you don't modify the collection / data source in the first parameter of the function. In your example, this expression in the button's OnSelect:

AddColumns(Destinations,"State",State1)

Does not modify the Destinations collection. It returns a new collection, with an additional column, and since that collection is not being used (e.g., assigned to a control Items property, collected to another collection, etc), then its value is discarded.

 

The AddColumns is used mostly to create a "calculated" column, whose value is based on the values of the other columns. Going back to the expression above, if the collection Destinations had, say, 10 items, then the collection returned would have a column "State" with the value of the text input for all of the items, which is probably not what you intended.

 

Take a look at the updated app at https://1drv.ms/u/s!AonXZuy7S5iZiZEQB4UMKb7cn7FIEQ. It shows an example of the AddColumns taking the value of an existing column (e.g., CityState) and creating a new column based on that (e.g., extracting the city part). Or in the original example of this thread - taking a column with a numeric value, and creating a new column that formats it as we want.

 

Hope this helps!

View solution in original post

Thanks for the assistance

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (2,329)