Power BI and Microsoft 365 / practical developer guides

DAX User-Defined Functions 2026: Complete Power BI Guide

A reusable function should make a calculation easier to test, not hide its filter context. Start with a simple scalar function, save it explicitly, then introduce deferred expressions only where the function must control evaluation context.

Documentation reviewed 2026-10-30. Start small, inspect the evidence, test the permission boundary.

1. Where UDFs help, and what they do not replace

A UDF packages parameterized DAX logic for reuse in measures, calculated columns, visual calculations or other UDFs. Functions are first-class model objects visible under Functions in Model explorer. Use them for a repeated rule with a clear contract: inputs, output behavior, units and filter-context expectations.

UDFs do not load data, create Fabric pipelines or provide a callable Python service. Reusing the code does not automatically change all callers into one measure, reduce query cost or make a flawed business rule correct.

Names must be unique and valid: alphanumeric/underscore characters, with periods allowed for namespacing. No spaces, reserved words or collisions with built-in functions; no starting/ending period or consecutive periods. A convention such as Finance.Margin is helpful, but capitalization is not an enforcement mechanism.

Microsoft reference: DAX UDF grammar, current limits, persistence, modes and security.

2. Define, evaluate and explicitly save a first function

In DAX query view on a practice model with a table, run this bounded example, adapted from Microsoft’s AddTax sample. It has no dependency on your Sales schema:

DEFINE
    FUNCTION AddTax =
        ( amount : NUMERIC, taxRate : NUMERIC = 0.1 ) =>
            amount * ( 1 + taxRate )
EVALUATE
    ROW (
        "DefaultRate", AddTax ( 10 ),
        "ExplicitRate", AddTax ( 10, 0.2 ),
        "ZeroAmount", AddTax ( 0 )
    )

Expected: DefaultRate = 11, ExplicitRate = 12 and ZeroAmount = 0. Decimal display can vary with formatting. This validates simple arithmetic/default behavior, not a tax-compliance rule.

To persist it, select Update model with changes or the single-function Update model: Add new function action. Then run a fresh query without DEFINE that calls AddTax(10). That separates a query-scoped function from an actually saved model object.

TMDL view can also apply a createOrReplace function script; Model explorer supports creation/editing through the formula bar. In a TMDL project, saved model definitions appear in definition\functions.tmdl. A saved query tab is not that model definition.

Back up or commit the baseline before updating a function already used by reports. The first successful query is not approval to replace a shared business rule everywhere.

Microsoft reference: DAX UDF grammar, current limits, persistence, modes and security.

3. Types, modes, defaults and the actual parameter limit

Current Microsoft documentation supports 0 to 256 parameters, not the older 12-parameter claim. Use as few as the contract needs; the maximum is not a design target.

Type familyExamplesMode and meaning
ValuesAnyVal, Scalar, TableDefault val; expr can defer evaluation.
ReferencesAnyRef, MeasureRef, ColumnRef, TableRef, CalendarRefexpr required; val is not allowed.
Scalar subtypesInt64, Decimal, Double, String, DateTime, Boolean, Numeric, VariantConstrain/coerce scalar inputs as documented.

Hints follow [type] [subtype] [parameterMode]. A numeric subtype implies Scalar. With no hints, a parameter behaves as AnyVal val. Value types support implicit casting; reference types do not.

val evaluates once in the caller’s context before invoking the function. expr defers evaluation until referenced inside the function, potentially under changed context and multiple times. An unused expr parameter is not evaluated.

A default expression makes a parameter optional. Optional positions can be skipped with an empty argument, but the rightmost required parameter still determines minimum argument count. Defaults resolve names at the function’s definition scope, cannot refer to another optional parameter and follow the parameter’s mode. Test omitted arguments and explicit values separately.

Microsoft reference: DAX UDF grammar, current limits, persistence, modes and security.

4. A valid val-versus-expr experiment

A fixed text parameter such as a document-type code can be entirely valid with val. Changing it to expr is not a universal fix for CALCULATE. The real question is whether the expression being aggregated must be evaluated after a context change.

Microsoft’s table example is a clearer diagnostic. This assumes an actual Sales table, related Date table and existing Date[Fiscal Year] field with the value FY2020:

DEFINE
    FUNCTION CountRowsNow = ( t : TABLE VAL ) =>
        COUNTROWS ( CALCULATETABLE ( t, ALL ( 'Date' ) ) )
    FUNCTION CountRowsLater = ( t : TABLE EXPR ) =>
        COUNTROWS ( CALCULATETABLE ( t, ALL ( 'Date' ) ) )
EVALUATE
    ROW (
        "ValueMode", CALCULATE (
            CountRowsNow ( 'Sales' ), 'Date'[Fiscal Year] = "FY2020"
        ),
        "ExpressionMode", CALCULATE (
            CountRowsLater ( 'Sales' ), 'Date'[Fiscal Year] = "FY2020"
        )
    )

With a valid relationship and multi-year data, value mode receives an already-filtered table; expression mode evaluates under the removed Date filter. Compare them to independently calculated FY2020 and all-year row counts. Microsoft’s sample counts are not universal expected values for your model.

For scalar measures inside iterators, distinguish row context, filter context, implicit measure context transition and parameter evaluation mode. expr alone does not insert CALCULATE around an arbitrary expression. MeasureRef deliberately restricts a parameter to a measure; AnyRef is broader. Test the actual reference/expression at row and total levels rather than applying a blanket CALCULATE workaround to every parameter type.

Use fully qualified column names. The current documentation flags unqualified column references as a known limitation for formula fix-up and dependency tracking.

Microsoft reference: DAX UDF grammar, current limits, persistence, modes and security.

5. Time intelligence and calculation groups remain different

A time-period function can receive a deferred measure/expression and evaluate it inside CALCULATE with a Date filter. Before standardizing that pattern, confirm the date table, relationship, intended calendar and behavior for partial periods. A reusable function does not fix a missing relationship.

Calculation groups apply selected-measure transformations and can provide report-facing calculation items. UDFs are explicitly invoked with arguments. You can combine them, but neither a UDF name nor a slicer automatically applies the function to all measures.

For example, keep a shared status-color rule in a UDF and let measures call it explicitly; preserve each measure’s targets and blank handling. For time intelligence, test the base measure, period selection and total before replacing duplicated expressions.

Do not migrate every calculation group merely because UDFs exist. Decide from parameterization, selected-measure behavior, dynamic formats, caller clarity and regression coverage. A one-line shared function can still require many caller-level tests.

Microsoft reference: DAX UDF grammar, current limits, persistence, modes and security.

6. Test the contract and deploy an actual model definition

  • Scalar checks: positive, zero, negative, blank, wrong-type and omitted-default inputs appropriate to the business contract.
  • Context checks: one entity, multiple entities, selected dates, no matching rows and grand totals. Check expected units and result types.
  • Persistence: a fresh query without DEFINE and a model-definition diff.
  • Dependencies: changed and unchanged callers, relevant security identities and representative reports.
  • Performance: compare representative queries; fewer lines of DAX do not prove a faster query.

Model explorer’s Evaluate and Define and evaluate quick queries help build tests. EVALUATE INFO.USERDEFINEDFUNCTIONS() returns saved model UDF metadata and requires Write permission; a query-scoped definition is not proof of deployment. Use /// comments for the supported function-description experience, but do not promise parameter descriptions where the limitations page says they are unsupported.

Keep reviewed functions/tests in source control using TMDL. A separate semantic model holding a function library is not automatically a remote import mechanism. Copying definitions requires dependency, version and license review; consumers do not silently inherit future edits from the source library.

Community libraries such as daxlib.org can be useful starting points, not proof of correctness, portability or permission for every use. Review the chosen function’s dependencies/license and test it against your own model.

Microsoft reference: DAX UDF grammar, current limits, persistence, modes and security.

7. Current boundaries and security qualifications

  • Compatibility level 1702 or higher; UDFs are unsupported in models with no tables.
  • No recursion/mutual recursion, overloading or explicit return type.
  • No native hide/unhide, display folders or translations for UDFs; parameter descriptions are unsupported.
  • No enum return for use in built-in enum-parameter positions.
  • No define-with-references quick query; do not infer support from an older screenshot.
  • Live-connected report measures can call source-model UDFs without IntelliSense; composite-model model measures cannot call source-model UDFs.
  • Visual calculations can use UDFs but only with fields in that visual. They cannot gain arbitrary model access by passing hidden model objects to a function.

OLS does not automatically transfer to a function. If a function refers to a secured object and runs under a user without that object’s access, the reference behaves as missing. Avoid leaking secure object names through function names/descriptions and test restricted identities. This is not a general OLS bypass or a promise that function metadata is hidden.

IntelliSense support varies in visual calculations, VS Code TMDL tooling and SSMS. Parser inconsistencies are documented for advanced expression/column-reference cases. Validate execution and results in a practice model instead of accepting every red underline as the same failure or claiming that all DAX contexts are supported.

Microsoft reference: DAX UDF grammar, current limits, persistence, modes and security.

Common questions

Are DAX UDFs generally available?

Yes. Microsoft documents GA in Desktop and Service as of June 2026, with compatibility level 1702 or higher. DAX UDFs are semantic-model functions, not Fabric User Data Functions or SQL/M functions.

How many parameters can a DAX UDF have?

Current documentation supports 0 to 256 parameters. Parameters can have type hints, evaluation modes and optional default expressions. The older 12-parameter claim is not the current limit.

Does running DEFINE FUNCTION save it to the model?

No. A query definition can exist only in that query. Use Update model with changes or the single-function save action, then verify from a fresh query without DEFINE and inspect the persisted definition.

Should every CALCULATE-related argument use expr?

No. Stable scalar values can correctly use val. Use expr when the function must evaluate the supplied expression under its own context. Evaluation mode, references and context transition must be tested separately.

Can a shared semantic model automatically distribute its UDFs to all other models?

No automatic shared-library import is established by storing functions in another model. Copy or deploy reviewed definitions and dependencies through a supported workflow, version them and test each consuming model.

Official references and review scope

Checked against the following official vendor documentation on 2026-10-30. This is an independent learning guide, not a Microsoft certification, benchmark or customer deployment report. These workflows have not been executed in your tenant. Expected values are teaching acceptance checks; validate feature availability, identity, network, schema, data handling and recovery requirements before production use.

Scroll to Top