DAX User Defined Functions Power BI: The Enterprise Guide to Reusable Reporting Logic
A DAX user defined function is defined once in the semantic model and called from measures, calculated columns, visual calculations and other functions.
DAX user defined functions Power BI teams have waited for are now generally available. Enterprise semantic models collect the same variance, tiering and business-hours logic in dozens of measures, and each copy drifts over time. A user defined function (UDF) lets you write that logic once, give it a name and call it everywhere, which makes reporting cheaper to audit and faster to change.
This guide is for BI leaders and model owners. It covers how UDFs work, how to define them, the difference between model-dependent and model-independent functions, and how to govern a shared function library.
DAX User Defined Functions Power BI: What They Are
Microsoft describes DAX UDFs as a way to package reusable, parameterized DAX logic. They introduce a FUNCTION keyword, accept scalar, table and reference parameters, and can be called from a measure, calculated column, visual calculation or another UDF. They are first-class model objects, listed under the Functions node in Model explorer. Microsoft states that UDFs are generally available in Power BI Desktop and the Power BI service from the June 2026 release, and that they need database compatibility level 1702 or higher.
That status matters. Earlier guidance, including older versions of this article, treated UDFs as a preview feature or as a naming pattern built from hidden measures. Neither is correct today, so retire any preview-only caveats from your standards.
Why Enterprise Reporting Teams Need Them
The business case is rule changes. When a margin threshold, tax rate or tiering band changes, every measure that copied the rule must be found and edited. Common candidates include variance and budget comparisons, SWITCH-based tiering and RAG status, and business-hours elapsed time. A UDF turns each into one governed definition, so finance and operations reports calculate the same number the same way. Business-hours logic is a good example: the same weekend and holiday arithmetic applies to ticket resolution and invoice approval, so one function can serve both.
How to Define a DAX UDF
You can author UDFs in DAX query view, TMDL view or Model explorer. DAX query view suits development because you can test with EVALUATE before saving. TMDL view suits teams that script and version-control the model. Microsoft recommends /// description lines, including @param and @returns tags, so the documentation shows in IntelliSense.
DEFINE
/// Variance of actual against target, as a ratio
FUNCTION Finance.VariancePct = (
actual : NUMERIC,
target : NUMERIC
) =>
DIVIDE ( actual - target, target )
EVALUATE
{ Finance.VariancePct ( 110, 100 ) }
-- Returns 0.1 (illustrative)
Function names can use dots for namespacing, such as Finance.VariancePct, but cannot contain spaces or special characters, and cannot clash with built-in functions or reserved words.
Parameters: Type Hints and Value Versus Expression
Each parameter can carry optional hints: a type, a subtype for scalars and a passing mode. Microsoft documents the following.
| Hint | Options | What it controls |
|---|---|---|
| Type | AnyVal, Scalar, Table, AnyRef, CalendarRef, ColumnRef, MeasureRef, TableRef | What the parameter accepts |
| Subtype | Variant, Int64, Decimal, Double, String, DateTime, Boolean, Numeric | The scalar data type |
| Passing mode | val (eager), expr (lazy) | When the argument is evaluated |
The passing mode is where most mistakes happen. A val parameter is evaluated before the function runs, in the caller's context. An expr parameter is evaluated inside the function, so the function can change the filter context around it. Reference types such as ColumnRef and MeasureRef must be expr.
Model-Dependent Versus Model-Independent UDFs
A model-dependent function hardcodes tables, columns or measures. It centralizes logic inside one model but breaks if copied to another with different names. A model-independent function receives everything as parameters. Reference parameters make this possible for calculations that must touch model objects.
-- Model-dependent: breaks without FactSales and 'Date'
FUNCTION YtdSales = () =>
CALCULATE ( SUM ( FactSales[Sales] ), DATESYTD ( 'Date'[Date] ) )
-- Model-independent: references arrive as parameters (illustrative, test in your model)
FUNCTION Reporting.Ytd = ( m : MEASUREREF, dateCol : COLUMNREF ) =>
CALCULATE ( m, DATESYTD ( dateCol ) )
-- Thin model-specific call
Revenue YTD = Reporting.Ytd ( [Total Revenue], 'Date'[Date] )
| Characteristic | Model-dependent | Model-independent |
|---|---|---|
| Model references | Hardcoded | Passed as parameters |
| Portable across models | No, rewrite per model | Yes, same definition |
| Maintenance point | Each model | One shared definition |
| Best for | Reducing duplication in one model | A shared library across many models |
Where a function stays model-dependent, treat it as a documented exception. Where it can be model independent, put it in the shared library.
- DAX user defined functions are generally available from the June 2026 Power BI release.
- Define them with the FUNCTION keyword in DAX query view, TMDL view or Model explorer.
- Use type hints and the val or expr passing mode to make functions safe and predictable.
- Pass tables, columns and measures as reference parameters to keep functions portable.
- Govern a shared library with naming rules, mandatory descriptions and version control.
Where to Call a UDF and How It Differs From a Measure
Once saved, a UDF is called like a built-in function.
| Call site | Example | Note |
|---|---|---|
| Measure | AddTax ( [Total Sales] ) | Full filter context |
| Calculated column | CONVERT ( AddTax ( 'Sales'[Sales Amount] ), CURRENCY ) | Return a consistent scalar type |
| Visual calculation | AddTax ( [Sales Amount] ) | Only fields in the visual |
| Another UDF | AddTax ( amount - discount ) | Compose small functions |
UDFs do not replace measures. A measure returns a result in filter context, while a UDF is a parameterized routine that measures call.
Governing Your DAX User Defined Functions Power BI Library
Treat the library like code. Agree a namespace convention such as Finance. and Reporting. before the first function ships. Make the description mandatory. Script functions in TMDL so changes are reviewable alongside the rest of the model, and use INFO.USERDEFINEDFUNCTIONS() to inventory them, which Microsoft notes needs write permission. Extract a UDF when the same logic appears in three or more places. Our TMDL guide covers scripting, and our DAX SELECTEDMEASURE guide covers a companion pattern.
Our Power BI consulting team builds function libraries and measure standards, and the Power BI Governance Platform helps you monitor model quality at scale. Speak with a certified consultant to audit your measures and plan your first governed UDF library.