Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric Data Days Monthly is back. Join us on March 26th for two expert-led sessions on 1) Getting Started with Fabric IQ and 2) Mapping & Spacial Analytics in Fabric. Register now

Ilgar_Zarbali

Understanding the Differences Between DAX UDF and Fabric UDF in Power BI and How to Use Them

Power BI provides robust tools for data modeling and analysis, including support for User Defined Functions (UDFs). Within Power BI, two primary types of UDFs are available: DAX UDFs and Fabric UDFs. This article presents a detailed overview of both, highlighting their key differences, strengths, and best practices for effective implementation.

User Defined Functions (UDFs) enable users to create reusable logic by encapsulating complex calculations or operations into custom functions. In the Power BI ecosystem, UDFs improve efficiency, consistency, and maintainability by allowing the same logic to be reused across reports, semantic models, and data pipelines, ultimately enhancing both analytical flexibility and development productivity.

 

Understanding DAX user-defined functions

DAX User Defined Functions (UDFs) are custom functions created using the Data Analysis Expressions (DAX) language within Power BI semantic models. They enable the reuse of DAX logic in a way that is comparable to calculation groups, but with a more focused and modular scope.

DAX UDFs allow developers to encapsulate DAX expressions into reusable functions that behave like native DAX functions. They introduce a dedicated FUNCTION keyword, support optional parameters—including scalar, table, and reference types—and provide type-checking helpers that improve clarity and reduce errors during development. Once defined, a DAX UDF can be used in measures, calculated columns, visual calculations, or even nested within other user-defined functions. This approach helps centralize business logic, enhances maintainability, and allows calculations to evolve safely over time. DAX UDFs are treated as first-class objects in the semantic model and can be created and managed through DAX Query View and TMDL View, as well as accessed in the Model Explorer under the Functions node.

 

Enable user-defined functions

To test UDFs in Power BI Desktop:

  1. Open File → Options and settings → Options.
  2. Go to Preview features and enable DAX user-defined functions.
  3. Click OK, then restart Power BI Desktop to apply the changes.

Create and manage user-defined functions

User-defined functions can be created and maintained in several places:

  1. DAX Query View (DQV): Functions can be defined and edited directly in DQV. This view also provides context-menu quick queries—such as Evaluate, Define and evaluate, and Define all functions in this model—to help test and manage UDFs efficiently.
  2. TMDL View: UDFs can also be written and modified in TMDL. The TMDL view includes a Script TMDL option in the context menu to assist with authoring and managing functions.
  3. Model Explorer: Existing user-defined functions are displayed under the Functions node in the Model Explorer.

When creating a UDF, the following naming rules apply:

Function names:

  • Must be valid and unique within the model.
  • May include periods for namespacing (for example, Microsoft.PowerBI.MyFunc), but cannot begin or end with a period, nor contain consecutive periods.
  • Aside from periods, may only use alphanumeric characters and underscores—spaces and special characters are not permitted.
  • Must not conflict with built-in DAX functions or reserved keywords (such as measure, function, or define).

Parameter names:

  • May include only alphanumeric characters and underscores; periods are not allowed.
  • Must not use reserved keywords.

 

Example Use Case

A customer needed a method to share DAX logic without revealing the full query. By using a DAX user-defined function, they were able to encapsulate the logic into a function that returns a filtered table based on parameters such as customer name or product. Other users can then invoke this function to retrieve only the specific data they require.

 

How to Create a DAX UDF

In DAX Query View, functions are created using the `DEFINE FUNCTION` syntax:

 

DEFINE FUNCTION FunctionName (parameters) = expression

 

For example, a function that calculates a discounted sales amount based on a given discount rate might look like:

 

DEFINE
FUNCTION Sales.DiscountedAmount =
( SalesAmount : DECIMAL, DiscountRate : DECIMAL ) =>
SalesAmount * ( 1 - DiscountRate )

 

This function calculates the discounted sales amount by applying a specified discount rate to the original value.

 

1.png

 

What Are Fabric User Defined Functions?

 

Fabric User Defined Functions (UDFs) are an additional type of custom function available within the Microsoft Fabric ecosystem, designed to integrate seamlessly with Power BI and other Fabric services.

 

User data functions enable developers to host and execute their own code directly in Fabric, allowing business logic to be written once and reused across the platform. This capability supports the Python 3.11.9 runtime, provides access to public libraries from PyPI, and enables connectivity to Fabric data sources and services, offering a flexible and extensible way to embed custom processing into Fabric workflows.

 

Key Characteristics of Fabric UDFs

 

  1. Defined within Fabric workspaces: Unlike DAX UDFs, Fabric UDFs are authored and managed directly inside Fabric workspaces.
  2. Dependent on the Fabric platform: These functions run exclusively within the Microsoft Fabric environment.
  3. Reusable across Fabric services: Fabric UDFs can be invoked from Power BI reports, data pipelines, notebooks, and other Fabric components.
  4. Action-oriented execution: Rather than simply returning values, Fabric UDFs often perform operational tasks such as writing to SQL databases, removing data, or calling external APIs.
  5. Implemented in Python: Fabric UDFs are written in Python, enabling advanced data processing, automation, and integration scenarios.

 

Example Use Case

A common use case involves leveraging Fabric UDFs in translytical workflows within Power BI to write data back to a SQL database or carry out other data manipulation operations.

 

Integration

Fabric UDFs work seamlessly with translytical applications and other Fabric services, extending capabilities well beyond traditional data modeling.

 

Summary of Differences Between DAX UDF and Fabric UDF

DAX UDF

 

  • Added to semantic model
  • Can be used in any DAX

 

Fabric UDF

 

  • Added to the report
  • Can be used as part of translytical task flows

 

2.png

 

Conclusion
Understanding the distinctions between DAX UDFs and Fabric UDFs is essential for Power BI users and developers who want to optimize their data models and workflows. DAX UDFs offer an effective way to package and reuse DAX logic within semantic models, whereas Fabric UDFs broaden capabilities across the Fabric ecosystem by enabling Python-based functions that can handle more advanced and operational tasks.

Comments

Amazing blog thanks 😊