Value.As
ValueAsserts that a value is compatible with a specified type, raising an error if not.
Syntax
Value.As(value as any, type as type) as anyParameters
| Name | Type | Required | Description |
|---|---|---|---|
value | any | Yes | The value to assert and cast. |
type | type | Yes | The type to assert compatibility with. |
Return Value
any — The 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 | |
|---|---|
| 1 | 25 |
| 2 | 50 |
| 3 | 15 |
| 4 | 75 |
Compatibility
✓ Power BI Desktop✓ Power BI Service✓ Excel Desktop✓ Excel Online✓ Dataflows✓ Fabric Notebooks