ADNia is part of Cofomo

Learn more

DAX User-defined functions

3 minutes
DAX User-defined functions

Hatem Meddeb

Architect

DAX User-defined functions
Published : 16 March 2026
  • Valorization
  • Article
Share

In September 2025, a new feature was introduced in Power BI: User-Defined DAX Functions (UDFs) . This introduction represents a true revolution in the use of the DAX language. Developers are no longer limited to native DAX functions and no longer need to create measures with redundant and difficult-to-maintain logic. With UDFs, they can define their own functions, giving them greater flexibility in development.

1. The advantages for DAX development

  • Centralization and reusability: A business rule is defined only once and can be used in multiple measures, calculated columns, visual calculations, or other user-defined functions.
  • Simplified evolution and maintenance: Modifying a function automatically updates all dependent calculations.
  • Portability: Functions can be grouped into libraries and shared between different semantic models.
  • Readability: Measures are more readable by replacing complex blocks with function calls.
  • Fewer errors: The use of type indicators and checking functions makes the function more error-resistant.

2. Definition and integration into the model

Before you can try out user-defined functions, you must enable them in the “features coming soon” section of the Power BI desktop options.

Activer

Functions can be defined either in the DAX query view (DQV) with the DEFINE command , or in the TDML (Tabular Model Definition Language) view with the createOrReplace command. 

Vue de requête DAX (DQV)

The syntax of a user-defined function is as follows:

FUNCTION <FunctionName> = ([ParameterName]: [Type] [SubType] [Mode], …) =>

<Function body>

Exemple de comment écrire la fonction DAX

The function name must be unique within the model; it may contain periods, but no spaces or special characters. It must not be the name of a built-in DAX function or a reserved word.

 

A user-defined function can accept zero or more parameters. A parameter name can contain alphanumeric characters or underscores “_”. It must not be a reserved word.

 

For each parameter defined in the function, the [Type] [SubType] [Mode] flags can be specified. If they are not, the default value “anyval val” will be used.

 

 

These indicators are summarized in the following table:

Type Subtype Mode Remarks
anyval val Accepts any type of scalar data or a table. This is the default type.
scalar val / expr Accepts a scalar value.
variant val / expr Accepts a scalar value.
Int64 val / expr Accepts an integer.
Decimal val / expr Accepts one decimal place with fixed precision.
Double val / expr Accepts one decimal place with fixed precision.
String val / expr Accepts text.
Datetime val / expr Accepts a date/time.
Boolean val / expr Accepts True/False.
Numeric val / expr Accepts a numerical value.
Table val / expr Accepts only one table.
Anyref expr Accepts a reference to a table, column, measure, or calendar.

The “mode” indicator defines how parameters are passed and influences the behavior of the function.

 

If the mode is “val”, the parameter is evaluated immediately before the function call and its value is fixed. Conversely, if it is “expr”, it is evaluated within the function body and changes according to the internal context.

 

A user-defined function can have built-in documentation. Using “///” directly above the function allows a description to be displayed in the tooltip when it is used. This differs from “//” or “/**/” which are used for comments.

 

Once a user-defined function is registered in the model, it is called in the same way as built-in DAX functions.

 

All user-defined functions can be displayed from the model explorer under the “Functions” node or via the DMV (Dynamic Management Views) query “EVALUATE INFO.FUNCTIONS(“ORIGIN”, “2”)”

Données -> Modèles -> Fonctions

DAX, Démonstration

3. Current limitations

  • No recursion: A function cannot call itself.
  • No optional parameters: All arguments of a function are required.
  • OLS security: User-defined functions do not inherit object-level security.
  • Refactoring: Renaming an object used in a UDF does not automatically update the function code.

4. Conclusion

With the arrival of user-defined functions in Power BI, DAX is moving from a formula expression language to a flexible and modular programming tool that allows business logic to be separated from the presentation layer.

 

 

Reference :

https://learn.microsoft.com/en-us/dax/best-practices/dax-user-defined-functions

With ADNia, explore new perspectives to take your data — and your impact — even further.

Keep exploring with insights, analyses, and best practices on the same topic.

Flèche
Learn more
Flèche