How to Replace Position of First Name and Last Name in Power Apps?

One day, one of my clients asked me to display the currently logged-in user name in a reverse manner in Power Apps (For example, Annie Husen -> Husen Annie). At first, I thought it was pretty tricky. But later, after researching, I found it very easy to achieve using the Power Apps Split function.

In this tutorial, I will show you how to replace position of first name and last name in Power Apps. We will also discuss how to reverse the user’s first and last names from the SharePoint Text and Person fields.

Replace Position of First Name and Last Name in Power Apps For Current User

The screenshot below represents a Power Apps form with various fields (from the SharePoint list). I wanted to display the currently logged-in user name by default in the Employee Name field.

Usually, the current logged-in user’s full name is displayed with a combination of First and Last names. But here, I wanted to display the Power Apps current user name in reverse (Last name & First name), as shown below.

Replace Position of First Name and Last Name in Power Apps For Current User

To do this, I have used the formula below on the Employee Name field’s Default property:

Default = Last(
    Split(
        User().FullName,
        " "
    )
).Value & " " & First(
    Split(
        User().FullName,
        " "
    )
).Value

Where,

  • Split = Power Apps Split function breaks a text string into a table of substrings.
  • User().FullName = This function helps to retrieve the Power Apps current logged-in user’s full name
Replace Position of First and Last Name in Power Apps For Current User

This is how to reverse current user first name and last name in Power Apps.

Power Apps Reverse User Name From a SharePoint List

Here, we will see two cases to reverse the user name from a SharePoint list in Power Apps. Such as:

  • Power Apps reverse user name from a SharePoint text column
  • Power Apps reverse user name from a SharePoint person column

Power Apps Reverse User Name From a SharePoint Text Column

Next, we will see how to replace the position of a user name from a SharePoint text with a delimiter comma.

Below is a SharePoint list named Product Details. This list has a Text column (Employee Name) where I store the employee name.

Power Apps Reverse User Name From a SharePoint List

The Employee Name is stored in the SharePoint list, like “Graham, Miriam“. In Power Apps, there is a Gallery control. Inside the gallery, there is a label displaying the employee’s name from the SharePoint list. I would like to reversely display the employee name on the label, like “Miriam Graham” (excluding the delimiter comma).

Refer to the image below:

Power Apps Replace first name and last name from SharePoint list

To work around this, select the gallery label and set its Text property to the code below:

Text = With(
    {
        wString: Last(
            Split(
                ThisItem.'Employee Name',
                " "
            )
        ).Value & " " & First(
            Split(
                ThisItem.'Employee Name',
                " "
            )
        ).Value
    },
    Left(
        wString,
        Len(wString) - 1
    )
)

Where,

  • wString = Scope variable name
  • Employee Name‘ = SharePoint text column

Sometimes, while using this code, it removes the last letter of the user/employee name. In that case, you can remove the “-1” from the scope variable.

Reverse User Name From a SharePoint List in Power Apps

Power Apps Reverse User Name From a SharePoint Person Column

Let’s reverse the user name from a SharePoint person field in Power Apps.

Below is a Person column called Employees in the SharePoint list (Project Details). Here, the employee names are stored as First Name and Last Name.

I want to display these employee names in reverse order in Power Apps. For example, if the first employee’s name is “Patti Fernandez,”. I want to display the name “Fernandez Patti” in Power Apps.

Power Apps Reverse User Name From a SharePoint Person Column

Refer to the screenshot below:

Power Apps Reverse User Name From SharePoint

To achieve it, select the gallery label and set its Text property to the code below:

Text = With(
    {
        wString: Last(
            Split(
                ThisItem.Employees.DisplayName,
                " "
            )
        ).Value & " " & First(
            Split(
                ThisItem.Employees.DisplayName,
                " "
            )
        ).Value
    },
    Left(
        wString,
        Len(wString)
    )
)

ThisItem.Employees.DisplayName = As a SharePoint Person field, we must apply the employee column, including the “.DisplayName“.

Power Apps Reverse User Name From SharePoint Person Column

This way, we can reverse the user name from a SharePoint list in Power Apps.

I hope this article helped you learn how to replace the current Power Apps user’s first and last name. Additionally, we discussed how to reverse the user name from a SharePoint list text field and person field with various examples.

Moreover, you may like some more Power Apps tutorials:

>