DAX user-defined functions are now production-ready based on community feedback and internal validation. Their adoption during preview shows that DAX UDFs are quickly becoming a mainstay of Power BI semantic models.
Reusable, discoverable DAX building blocks
Now, DAX user-defined functions are ready to support production models at scale. With DAX UDFs, you can write a calculation once and reuse it across measures, columns, and visuals — instead of copying the same expression into multiple places and hoping they stay in sync. You can use /// documentation comments to make your functions self-describing — type a function name and IntelliSense shows the function description and the signature. Type hints control parameter passing behavior and enforce type safety at runtime.
You can break large monolithic DAX expressions into small, testable pieces that are easier to read, debug, and share with your team. And perhaps best of all, because DAX UDFs are first-class model objects with typed signatures and descriptions, you can let AI tools like Copilot discover and invoke them — giving language models a well-defined API into your business logic instead of raw DAX to guess at.
DAX user-defined functions let you turn your DAX expressions from individual semantic model assets into governed, reusable building blocks — supporting trusted, consistent analytics across your organization’s entire semantic layer.
Figure: Define once, reuse everywhere.
Define and call a UDF
Defining a UDF is straightforward. In a DEFINE block, declare your function, then call it in EVALUATE. You can define multiple functions — for example, a Margin function that calculates gross margin, and a Band function that calls Margin to classify the result into Strong, Moderate, or Weak, as in the following example. A UDF can invoke another UDF.
DEFINE/// Returns gross margin as a percentage of revenue./// Use for any profitability calculation across business lines.FUNCTION Margin = ( revenue : DECIMAL, cost : DECIMAL ) =>DIVIDE ( revenue - cost, revenue )/// Classifies margin into a performance band./// Strong >= 40%, Moderate >= 20%, otherwise Weak.FUNCTION Band = ( revenue : DECIMAL, cost : DECIMAL ) =>SWITCH (TRUE (),Margin ( revenue, cost ) >= 0.4, "Strong",Margin ( revenue, cost ) >= 0.2, "Moderate","Weak")EVALUATE{ Band ( 250000, 175000 ) } -- "Moderate" (30% margin)
Figure: Using DAX user-defined functions in Desktop.
Try adding these UDFs to a model, as in the previous screenshot, then type Band in DAX Query View and hover the mouse over it. You can also use Ctrl + K followed by Ctrl + I shortcuts. IntelliSense shows the description, parameter names, and types. You can author functions wherever you’re most comfortable: DAX Query View for interactive exploration, TMDL View for code-first editing, the XMLA endpoint for programmatic automation, SQL Server Management Studio (SSMS), Semantic Link Labs in Fabric notebooks, or any third-party tool that connects to the semantic model.
Best practices for enterprise teams
Save your function definitions as TMDL files — the text-based format that describes your semantic model — and check them into a Git repository. Now every model creator in the organization can pull curated business logic from the same repository of approved functions — one source, no drift.
Consider building a Git-integrated shared function library model. Prefix function names with a team or domain label — Finance.Margin, Supply.LeadTime, HR.Attrition — so anyone reading the shared function library model knows immediately where a function belongs and who maintains it. Git integration automatically generates the .tmdl files in your workspace repo. Maintain your DAX function versions the same way you version code.
Figure: Using INFO.USERDEFINEDFUNCTIONS().
As in the previous screenshot, provide a description for every function (those /// documentation comments) so INFO.USERDEFINEDFUNCTIONS becomes a living catalog — searchable, auditable, and always in sync with what’s deployed. Note that INFO.USERDEFINEDFUNCTIONS() only returns functions that are saved to the model, for example, through Model Explorer in Power BI Desktop (right-click on “Functions” or select the “More options” button […] > New function). If you define your UDFs with DEFINE FUNCTION in a DAX query, they only exist for that query and won't appear in INFO.USERDEFINEDFUNCTIONS(), unless you add it to the model via CodeLens.
Use the XMLA endpoint — the all-powerful API for semantic models — to script function deployments across any number of semantic models in one automated loop. Leverage Semantic Link Labs in Fabric notebooks or any third-party tool that connects to the semantic model.
New capabilities now generally available
Improvements with this release:
- Web modeling: View and edit DAX UDFs in the browser with the same convenience as in Power BI Desktop. This allows teams to collaborate on function development and updates directly from any device, streamlining the authoring and maintenance process.
- Optional parameters: Specify a default expression for a parameter in the function signature to make a parameter optional. A UDF has the following grammar:
FUNCTION <FunctionName> = |
For example, given the following function using optional parameters:
FUNCTION AddNum = (x : NUMERIC = 1, y : NUMERIC = 2) => x + y |
One can invoke AddNum(), AddNum(1), AddNum(,2) or AddNum(1,2). If the caller omits the argument, the default expression is used as the argument value. The default parameter expression will respect type hints at runtime and can invoke other UDFs or built-in functions.
- A range of type hints is supported to offer expressiveness, flexibility and runtime type safety. Supported type hints are: AnyVal, Scalar, Table, AnyRef, CalendarRef, ColumnRef, MeasureRef, TableRef.
- Create and edit UDFs in Model View in Power BI Desktop: Use “New function” on the context menu to get started and then use the formula bar to modify the UDF expression.
- DAX UDF expressions saved in the model are kept in sync when you rename tables, columns, or measures. Object dependencies are tracked automatically.
- INFO.USERDEFINEDFUNCTIONS DMV: Returns a table with details about each UDF in the semantic model.
- SQL Server Management Studio (SSMS): UDFs are supported starting from version 22.5. You can script, create, and update UDFs using SSMS, although syntax highlighting for UDFs is not currently available in SSMS.
Comments
Post a Comment
Hi User,
Thanks for visiting My Blog and please provide your valuable feedback and subscribe for more updates. Please don't post any spam content or comments.
Thank You