Blog

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

If you're struggling with trailing commas in your Power Apps data, this post describes how to easily remove trailing commas from 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.
  •   Categories: 
  • data
Related posts