Data - How to remove trailing comma all rows in a table

In Power Apps, a common issue developers face is how to deal with trailing commas in data fields, which can lead to formatting problems and errors in data processing. 

This article describes how to remove trailing commas from all rows in a table using Power Apps.

Creating a Collection with Sample Data

To demonstrate the technique let's start by creating a collection with some sample data. The name of this collection is colEquipment.

This collection simulates a table with rows containing comma-separated lists of IT equipment. Note how some rows have trailing commas whereas others don't.

ClearCollect(
colEquipment,
{ID: 1, Items: "Laptop, Monitor, Keyboard,"},
{ID: 2, Items: "Mouse, Headset"},
{ID: 3, Items: "Printer, Scanner,"},
{ID: 4, Items: "Router, Modem"},
{ID: 5, Items: "Webcam, Microphone,"},
{ID: 6, Items: "Docking Station"},
{ID: 7, Items: "External Hard Drive, USB Hub,"},
{ID: 8, Items: "Projector, Screen"},
{ID: 9, Items: "Smartphone, Tablet,"},
{ID: 10, Items: "Speakers, Surge Protector"}
);

Here's how this collection looks when loaded into a data table control.


Applying the Logic to Remove Trailing Commas

To remove the trailing commas from the Items field in all rows of the collection, we can add a button and set the OnSelect property to the following:

UpdateIf(
colEquipment,
true,
{
Items: If(
Right(Items, 1) = ",",
Left(Items, Len(Items) - 1),
Items
)
}
);

In this formula, the UpdateIf function iterates through each row in the colEquipment collection.
  • The If function checks if the last character of Items is a comma.
  • If true, it removes the trailing comma using the Left function, which returns all characters except the last one.
  • If false, it retains the original Items value.

The screenshot below illustrates the result after running the formula. As we can see, all trailing commas have been removed.


Conclusion

To remove all trailing commas from all rows in a table within Power Apps, this post described how to call the UpdateIf function, conditionally check for a trailing comma, and remove it if present.

Related posts

Data - How to find the common rows from 3 or more collections
October 06, 2024
Data - How to show the distinct rows from 2 data sources or collections
February 26, 2024
Data - How to implement circular rotational date sorting
February 21, 2024
Bug - What to do when the data section of the Power Apps Maker portal doesn't work
June 18, 2023
Data - Combine columns from separate tables into a single table
October 13, 2022
Formula - Transposing/converting rows to columns- an almost impossible task?
September 23, 2021
Data - How to rename field names in a record
July 14, 2021
Data - How to hide duplicate rows in a gallery / show distinct multiple columns in a gallery
July 09, 2021
Data - Retrieving news/forum/blog articles with RSS
June 26, 2021
Data - How to sort by partial numbers in a text field
June 23, 2021
Data - How to return the last record from a table
June 19, 2021
Data - How to create bulk test/dummy records with random values
June 18, 2021
Data - 3 things you should know before using the MySQL or PostgreSQL connectors
May 11, 2021
Data - A walkthrough of how to migrate the data source of an app from Excel to Sharepoint
April 26, 2021
Data - How to enforce unique values (or prevent duplicate values) in one or more columns
April 19, 2021
Data - How much mobile data does Power Apps consume? What ways can we minimise this?
March 28, 2021
Data - How to save and retrieve Google calendar entries
March 14, 2021
Data - How to save and retrieve Google contacts
March 10, 2021
SQL - Caution! This is how users can hack shared SQL connections
January 23, 2021
SharePoint – 2 Mistakes to avoid when importing Excel data
January 10, 2021
SQL - Don't let this DateTime bug catch you out!
January 05, 2021
Settings - What's the purpose of the "Explicit Column Selection" Setting?
January 04, 2021
SQL Server for Beginners Part 3 - Installing On-Premises Gateway
January 24, 2019
SQL Server for Beginners Part 2 - Installing Management Studio
January 14, 2019
SQL Server for Beginners Part 1 - Installing SQL Server
January 04, 2019
Searching data–What you need to know about case sensitivity
December 27, 2018
Images - How to create images that can change depending on data
November 09, 2018
Excel - Reasons NOT to use Excel as a data source
September 25, 2018
SharePoint - What you need to know about Filtering Data
September 16, 2018
Formulas - Generating Row Numbers
April 05, 2018