Introducing the DAX Package Manager in Tabular Editor

Key Takeaways

  • User-Defined Functions are a significant improvement for reusability and maintainability of DAX. User-Defined Functions (UDFs) let us reuse instead of rewrite expressions, ensuring consistency of logic and enhancing maintainability by not producing copies.
  • DAX Lib is a valuable resource for model-independent UDFs. As an open-source repository of UDFs, DAX Lib is a valuable resource today and will become even more so in the future as more functions are added.
  • The DAX Package Manager in Tabular Editor 3 puts DAX Lib at our fingertips. We can load, remove and update packages with the push of a button. In the future, this will also be possible with private, organizational libraries, and not just DAX Lib.

This summary is produced by the author, and not by AI.


User-Defined Functions for DAX

One of the best ways to write DAX is to first break down the logic required into components and look for a similar pattern for which someone else has already put in the effort of testing and documenting. In most cases, one or more combined DAX patterns do the trick without having to do much but change the copied expressions to fit your models and validate the results are as expected.

DAX has recently seen several significant updates:

  • Visual-level calculations, which can simplify calculations by scoping them to single visuals instead of the entire semantic model, lowering the bar for deeper visual customization.
  • Custom calendars and time intelligence, which allow flexible time-based analyses with any calendar.
  • User-Defined Functions (UDFs) or DAX functions, which are a game-changer whether you're a DAX novice or ninja. Why? The power of functions.

Functions allow us to abstract away all sorts of complex logic and simply expose just the inputs that are relevant to achieve the desired output. With DAX functions, we can define those patterns as a function with parameters once and invoke them whenever we need with different arguments, instead of copy-pasting expressions full of business logic across models. We package complexity and re-use instead of rewriting it.

V001 Figure 2 - Diagram showing how DAX functions centralize complex logic like CALCULATE, SUMX, ALLEXCEPT, FILTER, and SUMMARIZE into portable packages that can be reused across models

DAX Lib

DAX functions can be defined for a specific semantic model and only be usable within that model (these are model-dependent functions), or in common libraries that exist outside of the semantic model. Those functions are model-independent and can be used across different semantic models.

DAX Lib is an open-source library of model-independent DAX functions where you can search for keywords and find packages that contain functions you can load into your semantic model by copying them into the TMDL view of Power BI Desktop. However, this can be problematic for the following reasons:

  • Large libraries have big scripts which are difficult to manage.
  • Updates to the library require manually re-updating the script; this is prone to issues.
  • The process can be tedious and doesn’t work for private libraries, for which you’d need to maintain your own private set of TMDL scripts. We discussed potential methods for private libraries in a previous article.

A moving average calculation, for example, becomes much simpler to implement with the DAX functions in the MovingAverage package of the TimeSeries library. DAX Lib lets us copypaste packages and all functions within into the semantic model in Power BI Desktop.

V001 Figure 3 - DAX Lib website search interface showing how to find and install DAX packages for Power BI, with a search for 'moving' returning the TimeSeries.MovingAverage package

V001 Figure 4 - Power BI report showing quarterly sales trends with 5-day and 7-day moving averages, demonstrating how the 7-day window smooths out weekend effects

V001 Figure 5 - Copying the TMDL script from DAX Lib website to paste into Tabular Editor for installing DAX function packages

V001 Figure 6 - You paste the TMDL script from DaxLib into the TMDL view to get the DAX function library in your model. The TMDL view has difficulties with the UDF syntax

Introducing the DAX Package Manager in Tabular Editor 3

In Tabular Editor 3, we have the DAX Package Manager that puts the functions in DAX Lib at our fingertips. In a few clicks we can load, update or remove a package from DAX Lib into our semantic model rather than copypasting and replacing references in long DAX expressions.

V001 Figure 7 - DAX Package Manager interface in Tabular Editor 3 showing the Browse tab with available packages from daxlib.org provider

V001 Figure 8 - Installing the TimeSeries.MovingAverage package in Tabular Editor 3 from the DAX Package Manager

Here too, we can find the TimeSeries package hosted on DAX Lib. Installation is as easy as clicking the ‘Install’ button (which will only show up if the model is of a Compatibility Level of 1702 or higher). In the future, packages from private and organizational libraries will also be supported.

V001 Figure 9 - TOM Explorer in Tabular Editor 3 showing installed DAX functions from the TimeSeries package in the Functions folder

Once installed, the packages are listed in the Functions folder of the TOM Explorer and their expressions can be viewed in the Expression Editor.

V001 Figure 10 - An example of the installed DAX function packages in Tabular Editor 3. DAX functions are shown, organized by their “namespaces”

The DAX expression needed for the measure of a 7 day moving average of sales amount becomes simple: invoke the function and enter the required model objects as arguments.

V001 Figure 11 - Creating a measure in Tabular Editor 3 using the TimeSeries.MovingAverage.Simple user-defined function with parameters for date column, time series table, lookback periods, and expression

If we’re unsure of which argument goes where in the function, we can hit the CTRL + Shift + Space shortcut to show the parameter info box that tells us what every parameter expects as argument.

V001 Figure 12 - Example of parameter information from a DAX function in Tabular Editor

In this simple example, a moving average with a window looking back 5 days and one with a window looking back 7 days paint a different picture: the weekend dips in sales amounts are smoothed out in the latter alternative because weekends are always included in the calculation of the average.

V001 Figure 13 - A diagram titled 'Two alternatives of the same function tell a different story' and a screenshot of a Power BI report showing a line chart with

When packages get updated by the authors, we can choose to update them individually, all at once, or downgrade if we prefer the previous version of a package.

V001 Figure 14 - A diagram titled 'Manage package versions by updating them all or by package' and a screenshot of a Tabular Editor 3 showing package version management in DAX Package Manager

In conclusion

DAX User-Defined Functions bring us into an era where the logic encoded in DAX expressions becomes portable and more easily maintainable within and across organizations. Public libraries like DAX Lib help us simplify by making it easier to re-use patterns to address common DAX scenarios.

In Tabular Editor 3, the DAX Package Manager puts DAX Lib at our fingertips and will soon be able to do the same for private and organizational libraries. As its name suggests, the DAX Package Manager is the one-stop shop for managing packages and their versions.

Related articles