Value.As

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 )

Other functions related to Value.As are:

BI Gorilla Blog

Last update: August 25, 2023 | Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/value-as
© 2023 BI Gorilla. All rights reserved. Content derived from Microsoft documentation is property of Microsoft Corp.