Expression.Identifier
ExpressionReturns the M source code representation of an identifier name.
Syntax
Expression.Identifier(name as text) as textParameters
| Name | Type | Required | Description |
|---|---|---|---|
name | text | Yes | The identifier name to convert to its M source code representation. |
Return Value
text — A 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}
}
)Input | M Representation | |
|---|---|---|
| 1 | MyIdentifier | MyIdentifier |
| 2 | My Identifier | #"My Identifier" |