define_udf
Define a DAX User-Defined Function in your Power BI model by providing typed parameters, a return type, and a DAX body expression. Automatically bumps compatibility level to 1702+ if lower.
Instructions
Define a DAX User-Defined Function (a net-new model object). The body carries its own typed parameters and return type. params is a comma-separated name:type list (type = Scalar | Table | ColumnRef | MeasureRef | AnyRef | Numeric | String; omit a type for an untyped param). UDFs need compatibility level 1702+, which is auto-bumped if lower. Inspect existing UDFs with list_udfs.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | function name, e.g. AddMargin | |
| params | No | comma-separated name:type params, e.g. amount:Scalar, cost:Scalar (optional) | |
| bodyDax | Yes | the function BODY DAX (the expression after =>), e.g. amount * (1 - cost) | |
| sessionId | Yes | ||
| returnType | No | return type: Scalar | Table (optional) | |
| description | No | description (becomes the /// doc comment) |