How to Get Tenant Name in Power Apps

When I was working on a Power Apps and Power Automate solution for a client who wanted to create SharePoint sites automatically.

Users would fill in details such as site title, internal name, storage quota, description, owners, members, and visitors in Power Apps. After submitting the form, Power Automate creates the SharePoint site using a REST API call.

I wanted this solution to be reusable. That means anyone should be able to import this solution into any tenant and use it without changing the app or flow.

To achieve this, we need to get the tenant name dynamically.

However, Power Apps does not provide any built-in function to get the tenant name.

I asked a few colleagues about this, and one suggested storing the tenant name in a SharePoint list and reading it in Power Apps. But this approach is not truly dynamic and requires manual updates whenever the solution is imported into a new tenant.

After some time, I got a better idea.

Since I am building this Power Apps inside a Solution, I created an environment variable in the solution. When someone imports the solution into their tenant, they only need to provide the SharePoint site URL. From that site URL, we can extract the tenant name dynamically and use it in Power Apps and Power Automate.

In this tutorial, I will show you how to get the tenant name in Power Apps using this approach.

Get Tenant Name In Power Apps

For this example, I created a Power Apps Solution with an Environment variable named Site Address.

How to get the Tenant name in Power Apps canvas apps

Then, I create a blank canvas app inside this solution.

Tenant name in Power Apps

Now I want to show the Tenant Name in the Power Apps.

To do this, follow the steps below:

  1. Open the Power Apps where you want to show the tenant name. Then, in the Data tab, click the + Add data.
get tenant name in Power App
  1. Then connect Environment Variable Definitions and Environment Variable Values from Microsoft Dataverse.
Consume Environment Variable in PowerApps
  1. Next, add a Text label to the Power Apps.
environment variables in Power Platform solutions
  1. In the Text property, provide the following formula:
LookUp(
    'Environment Variable Values',
    'Environment Variable Definition'.'Schema Name' = "tsinfo_GetTenantName",
    Value
)

Where:

  • LookUp(): LookUp searches for a single record in a table that matches a condition.
  • Environment Variable Values: This table stores the actual values of environment variables.
  • Environment Variable Definition: This is a lookup column that points to the definition.
  • Schema Name: The unique name of the environment variable.
  • tsinfo_GetTenantName: Name of the Schema.
  • Value: It returns the Value column (the actual stored value of the environment variable).
PowerApps get environment variables value
  1. Now you can see it will return the Site Address.
How to find your Microsoft 365 tenant name in Power Apps

Now that we have the Site Address in place, we can extract the tenant name from it.

  1. Next, add another text control and provide the formula below.
First(
    Split(
        Substitute(
            LookUp(
                'Environment Variable Values',
                'Environment Variable Definition'.'Schema Name' = "tsinfo_GetTenantName",
                Value
            ),
            "https://",
            ""
        ),
        "."
    )
).Value
How to Get Tantent Name In Power App
  1. Then you can see the tenant name in the Power Apps.
How to Get Tenant Name In Power App

In this tutorial, we learned how to get the tenant name in Power Apps. We used an environment variable to store the SharePoint site address and then extracted the tenant name from that URL.

Also, you may like some more Power Apps tutorials:

Power Apps functions free pdf

30 Power Apps Functions

This free guide walks you through the 30 most-used Power Apps functions with real business examples, exact syntax, and results you can see.

Download User registration canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App