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

In this first Power Platform 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.

Power Apps

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.

Unwanted Characters

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:

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! No more unwanted characters 🥳

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

Thanks for reading! 🙂

Discover more from Veronique's Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading