<!-- https://learnsql.cpetoday.com/functions/dax/username -->
# USERNAME

Language: DAX
Category: Information
Syntax: USERNAME()
Summary: Returns the name of the user who is connected to the model.
Returns: Text (a scalar). The exact form depends on where the model runs.
Level: Beginner
Related: USERPRINCIPALNAME, LOOKUPVALUE, BLANK, IF, FORMAT, CONCATENATE

## What it does
USERNAME returns the name of the person who is using the model, as the host knows it. It is used to stamp a report with the name of the reader, or to look up the user's settings in a table. The exact text varies: a domain and user name in some hosts, a sign in name in others. Test it in the environment where the report will run.

## Syntax and arguments
USERNAME takes no arguments. Write `USERNAME()` with brackets.

## Example
A close checklist is printed for sign off. The footer should show who printed it, to create a simple record of the person who took the view.

```dax
Prepared By = "Prepared by " & USERNAME()
```

The footer reads "Prepared by" followed by the user's name as the host supplies it. The name is generated when the report is viewed, so the footer changes for each reader.

## Example: a second, different use
Show a user's own region by looking their name up in a table of user settings:

```dax
My Region =
LOOKUPVALUE(
    UserRegions[Region],
    UserRegions[UserName],
    USERNAME()
)
```

LOOKUPVALUE finds the row whose user name matches, and returns that row's region. If the user is not in the table, the result is BLANK.

## Things to watch
- The exact text of USERNAME varies by host. A lookup table must hold the same form the host returns.
- USERNAME is not a security control on its own. Use row level security in the model for access rules.
- Prefer USERPRINCIPALNAME when a stable email style identity is needed, because it is usually the same across hosts.
- Test in the environment where the report is published, not only in the desktop tool.
- A user name in a footer can be useful for audit trail, but it is not a signature.

## In business terms
USERNAME stamps reports with who viewed or prepared them, and it lets a model show each reader only their own unit when the lookup list is kept up to date. Auditors look for this kind of trail on a report that others will rely on.
