top of page
Search
  • Ahmed Sulaiman

A Descriptive Guide to Using TMDL for Power BI DAX Query Creation and Editing

Updated: 1 day ago

In recent updates, Power BI introduced a new feature called Tabular Model Definition Language (TMDL), which allows users to create and edit DAX measures and other elements more efficiently. This guide will walk you through the basics of TMDL, its benefits, and how to use it effectively for batch editing DAX measures.

What is TMDL?

Tabular Model Definition Language (TMDL) is a format designed to store the semantic model of Power BI projects. It enables users to manage and edit Power BI files using any text editor, providing a more streamlined and collaborative development experience. This feature is especially beneficial for source control and batch editing of measures.

Why Use TMDL?

1. Batch Editing: Edit multiple DAX measures simultaneously without having to manually create each one in the Power BI interface.

2. Source Control: Manage changes to your Power BI files through source control systems like Git.

3. Collaboration: Facilitate collaborative development by allowing multiple users to work on the same project files.

Setting Up TMDL in Power BI

1. Enable TMDL Format:

   - Go to Options and settings > Options in Power BI Desktop.

   - Under Preview features, check the box for Store semantic model using TMDL format.

   - Restart Power BI Desktop for the changes to take effect.

2. Save Project as PBIP:

   - Save your Power BI report as a Power BI Project file (`.pbip`).

   - This will create a project folder containing several files, including the semantic model in TMDL format.

Editing TMDL Files

Using Visual Studio Code

1. Open TMDL Files:

   - Install Visual Studio Code (VS Code) and the TMDL extension from the VS Code marketplace.

   - Open the folder containing your .pbip project files in VS Code.

2. Edit Measures:

   - Navigate to the definition folder and open the relevant .tmdl file.

   - Use the TMDL syntax to edit existing measures or create new ones.

Basic TMDL Syntax

A TMDL file contains blocks of code representing tables, columns, and measures. Here's a breakdown of the syntax for editing measures:


- name: The name of the measure.

- expression: The DAX formula for the measure.

- formatString: The format string for displaying the measure.

Creating a New Measure

To create a new measure, add a new JSON block within the appropriate table:



Batch Editing Measures

1. Duplicate Measures:

   - Copy and paste existing measure blocks and modify them as needed.

   - Ensure each measure has a unique name.

2. Modify Expressions:

   - Change the DAX formulas within the expression field to meet your requirements.

Example: Batch Editing Measures

Suppose you have several measures that need to be updated from SUM to AVERAGE. You can quickly make these changes in the TMDL file:

Before:



After:



Tips for Using TMDL Effectively

1. Use VS Code for Syntax Highlighting: The TMDL extension for VS Code provides syntax highlighting, making it easier to read and edit your code.

2. Validate Syntax: Ensure your JSON syntax is correct to avoid errors when loading the Power BI file.

3. Backup Your Files: Before making significant changes, create a backup of your .pbip project files.

4. Leverage Source Control: Use Git or another version control system to track changes and collaborate with team members.

Conclusion

TMDL is a powerful feature that enhances the flexibility and efficiency of working with Power BI projects. By using TMDL, you can batch edit DAX measures, collaborate more effectively, and leverage source control for better project management. Whether you're a seasoned Power BI developer or new to the platform, integrating TMDL into your workflow can significantly improve your productivity and project organization.


Watch this video to see the TMDL in work:




3 views0 comments

Comments


bottom of page