Value.As

Value

Asserts that a value is compatible with a specified type, raising an error if not.

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

Syntax

Value.As(value as any, type as type) as any

Parameters

NameTypeRequiredDescription
valueanyYesThe value to assert and cast.
typetypeYesThe type to assert compatibility with.

Return Value

anyThe original value if it is compatible with the specified type. Raises an error otherwise.

Remarks

Value.As returns the value unchanged if it is compatible with the specified type. If the value is not compatible, an error is raised. This is useful as a runtime assertion to ensure data quality and catch type mismatches early in a query pipeline.

Unlike Value.Is which returns a boolean, Value.As either passes through the value or throws an error. Use Value.Is for conditional logic and Value.As for strict enforcement.

Examples

Example 1: Assert Sales UnitPrice values are numbers

let
    Prices = Table.Column(Table.FirstN(Sales, 4), "UnitPrice"),
    Asserted = List.Transform(Prices, each Value.As(_, type number))
in
    #table({"UnitPrice"}, List.Transform(Asserted, each {_}))
Result
UnitPrice
125
250
315
475

Compatibility

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