Value.As is a Power Query M function that returns the input value if it is compatible with the specified type. The function returns the value casted to the specified type if compatible, otherwise, it returns an error.
Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365
Syntax
Value.As(
value as any,
type as type,
) as any
Description
Returns the value if it is compatible with the specified type. This is equivalent to the “as” operator in M, with the exception that it can accept identifier type references such as Number.Type.
Examples
Cast a number to a number.
// Output: 123
Value.As( 123, Number.Type )
Attempt to cast a text value to a number.
// Output: [Expression.Error] We cannot convert the value "abc" to type Number.
Value.As( "abc", type number )
Related functions
Other functions related to Value.As are:
