Contents

Remove specific characters from values in PowerApps

 

Have you ever had the scenario where, you had values in SharePoint (or Dataverse) with a character, or the end of the value is not relevant for your app, and it should not be displayed? I did.

In this first PowerPlatform blog post, we’ll get rid of the end of the value that’s after a specific character. And we’ll also include getting rid of the character since it won’t be relevant nor nice to see anymore!
 

Setting up the scene

SharePoint

Let’s start by creating a SharePoint list, and a single line of text column in SharePoint. I’ll call it Ref Number. We’ll then create a couple of items for testing purposes.

For simplicity, we’re also going to use the Title column which is already present in the list.

/images/powerplatform-screenshots/remove-char-values-img1.png
 

PowerApps

From a PowerApps perspective, let’s connect our SharePoint list as a datasource, and just add a gallery to a screen, then configure the fields to be our Title and Ref Number.

As we only have 2 fields for this demo, we’ll choose the gallery layout to be only Title and subtitle.

/images/powerplatform-screenshots/remove-char-values-img2.png
 

Renaming labels
I’ve also renamed my labels in the Tree View to have appropriate names. And although we won’t reference them directly by name, this is a good practice.
 

Thinking though…

Now that we’re displaying the data we want in the gallery, if we look at the formula in the Text property of the Ref Number, we’ve got ThisItem.'Ref Number'. And we see the entire number as it is present in SharePoint.

We need to change the formula so we don’t get to see the /5 or /1 from the items. So we could trim everything after the / character, including the character itself?

BUT WAIT… Have you noticed that the other ones also contain a / character? 😱

This means, we need a condition to exclude the items which have N/A
 

Let’s do it!

Select the Ref Number field in the gallery, and navigate to the Text property. Insert the following formula:

Change to your column name
Make sure to change the 'Ref Number' to your own column name.
 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
If(
    ThisItem.'Ref Number' <> "N/A" && "/" in ThisItem.'Ref Number',
    Concat(
        FirstN(
            Split(
                ThisItem.'Ref Number',
                "/"
            ).Result,
            CountRows(
                Split(
                    ThisItem.'Ref Number',
                    "/"
                ).Result
            ) - 1
        ),
        Result
    ),
    ThisItem.'Ref Number'
)

 

And observe the results! 🥳

/images/powerplatform-screenshots/remove-char-values-img3.png
 

We’ve removed the /5 and /1 from the items and kept the N/A intact.
 

Thanks for reading!