Expression.Identifier

Expression

Returns the M source code representation of an identifier name.

Examples on this page use shared sample tables. View them to understand the input data before reading the examples below.

Syntax

Expression.Identifier(name as text) as text

Parameters

NameTypeRequiredDescription
nametextYesThe identifier name to convert to its M source code representation.

Return Value

textA text string containing the properly escaped M source code representation of the identifier.

Remarks

Expression.Identifier returns the M source code representation of an identifier (variable or step name). If the identifier name is a simple name that does not require escaping (no spaces or special characters), it is returned as-is. If the name contains spaces or other characters that require quoting, the function wraps it in the #"..." escaped identifier syntax used by M.

This is useful for dynamically building M expressions as text strings. When you need to reference a column or step name that might contain spaces, Expression.Identifier ensures the name is properly escaped for use in code generated for Expression.Evaluate.

### Escaping rules

  • Simple identifiers (e.g., MyIdentifier) are returned unchanged.
  • Identifiers with spaces or special characters (e.g., My Identifier) are returned as #"My Identifier".

Examples

Example 1: Serialize simple and complex identifiers

let
    Simple = Expression.Identifier("MyIdentifier"),
    WithSpace = Expression.Identifier("My Identifier")
in
    #table(
        {"Input", "M Representation"},
        {
            {"MyIdentifier", Simple},
            {"My Identifier", WithSpace}
        }
    )
Output
Input
M Representation
1MyIdentifierMyIdentifier
2My Identifier#"My Identifier"

Compatibility

Power BI Desktop Power BI Service Excel Desktop Excel Online Dataflows Fabric Notebooks