Gamechanger — Top 6 Benefits of TMDL View in Power BI

I have started using the new feature and here is how it can help Power BI Developers

AI-Image generated by Author

Microsoft has finally brought something that Power BI developers have been demanding for a very long time. TMDL View is here, available from the January Power BI update. For the unversed, TMDL is Tabular Model Definition Language, which is the script behind any Tabular model.

Though it’s still in preview and should not be tested on production data, developers can try it out and provide their feedback.

Although Microsoft had already provided the feature to save Power BI files as project files (.pbip file type) and store the semantic model in TMDL format last year, to actually leverage the files, one needed to rely on external tools like Tabular Editor.

But now, with this update, TMDL view is available to developers in the Power BI Desktop itself, making it easier to manage the semantic model objects.

And obviously, you need to enable this preview feature from Options and settings → Options → Preview feature → TMDL View.

Image By Author — TMDL View in Preview features
Here is how the TMDL view looks. You can see there is a new icon added on the left side pane for TMDL view. It’s similar to the DAX query code editor view they added last year, with the only difference being it’s not for DAX but for TMDL scripting for the model objects. We will discuss that in the later part of this blog.
TMDL View in Power BI Desktop

As it’s in preview, you can see at the top right of TMDL view they have provided the Share Feedback button for users to share their feedback on it and suggest any improvements.

You can also see a warning message at the top stating not all the changes are supported currently in TMDL scripting. You can refer to the changes that are supported in the below documentation by Microsoft.

👉 Power BI Desktop projects (PBIP) — Power BI | Microsoft Learn

Now, here is how to get started with it.

1. Full Visibility & Control of Model Metadata in One View

Once you have opened the TMDL view, you can drag individual objects like a Table, Column, or Measure on the screen. You can see the schema definition of all the objects in one place.

You can also multi-select the objects in one go and drag them to the TMDL view screen. Each drag-and-drop of objects will create as many script pages, which you can see at the bottom left.

Image by Author — Semantic Model metadata in single screen

2. Create Multiple Measures, Columns and Tables in One Go

Yes, you heard it right. Let me explain this with an example. Let’s say you have been asked to create KPIs that show profit on sales in each country.

Now traditionally, what would you do? You would go to the “New Measure” option, write the CALCULATE DAX expression as below.

Image by Author- Profit_USA measure

This measure is just for Country = USA. Now to do it for 10 other countries, you need to go to the “New Measure” option 10 times, write the expression, and wait for their evaluation to complete each time. Evaluation time can take longer depending upon the complexity of the measure.

Now to reduce your effort and save time, you can drag the measure in TMDL view and just copy-paste the code in new lines for 10 countries and hit the apply button at the top. Boom. In one go, you will have all your measures created.

Image by Author —Step 1: Drag the measure in the TMDL view

Image by Author — Step 2: Copy-paste the measure expression and change country name in each. Once done, hit the Apply button at the top left

Image by Author — Step 3: Enjoy! Woohoo, all the measure created in one go!

That was with measures; you can follow the same approach and create calculated columns and tables in one go as well.

3. Updating/Editing Multiple Objects in One Go

Similar to #2 of creating multiple objects in one go, you can also update or edit the object expressions at once.

Let’s understand this with the same example we saw previously. Now you need to update the measures you created by modifying the DAX expression to change countries for 5 KPIs.

Image by Author — Updating the measures in one go

As you can see, we have updated the DAX expressions for the bottom 5 measures, changing the name and country in the filter expression of Calculate. Now once you hit the Apply button, you can see the changes reflecting in the Data view.
Image by Author — Multiple measures updated

4. Re-Usability of Code — TMDL Scripts Can be Reused

This is one of the best features that the TMDL view is offering. You can now re-use the code used in scripting/updating one semantic model to update another semantic model.

This is particularly helpful when you have certain objects and formatting in your data model which you are using across reports.

Some examples are —

  1. Measure like [DataModelRefreshTime] which you use to show last update datetime of data model.
  2. Certain calculations with conditional formatting which you need in your other reports also.
  3. Calculated columns pertaining to extracted values form already existing columns.

And there are many more such objects which you might need to reuse.

Now let’s see how to re-use the code in another model.

Step 1 — Go to the script in the source data model which you want to reuse.

Step 1


Step 2 
— Remove the lineageTags from the specific definitions because they are specific to each model. (Don’t worry, your script will work without that)

Step 2

Step 3 — Now copy this code and open the new model in Power BI Desktop and then paste it in the TMDL view and hit “Apply”. That’s it, you have all the changes moved into the new semantic model.

5. Source Control is Much Easier Now

Earlier with the .pbip files, you could directly modify the semantic model definition in VS Code, but to be able to apply changes in the model, you needed to restart Power BI Desktop.

With TMDL view, it has become quite hassle-free now. You can script any object, make changes in the code editor and then apply those changes instantly to the model as needed, without requiring a restart.

6. Increased Efficiency of the Developers

With all the schema objects and definitions available on a single screen, developers will see a boost in their efficiency.

If you want to update the name of tables by appending “Dim” for dimension tables and “Fact” for fact tables, then you can do it by making use of the Find/Replace expression available with Ctrl+H and you can do it in one go, thus saving your time. Similarly, you can update other objects which need bulk updates.

Also, with the TMDL code editor, you have IntelliSense (though it needs improvement), expand/collapse, error diagnostics, and autocomplete features which make it at par with other code editors, giving you a similar dev experience.

Conclusion

And that’s about it for this piece. I hope this one on TMDL view gave some perspective on it and how it can help you in your Power BI report development works.

I’d also recommend you read the below deep dive piece from Microsoft on the TMDL preview feature:

They have mentioned in the above blog that they are working on more updates in the TMDL view and you can expect those changes soon!

I hope you enjoyed reading this piece and got something out of it. Do share your thoughts in the comments!


If you find my blogs valuable and want to support — Buy Me A Coffee 
or click the image below 👇.

Thank You!!!

Follow me here 👇:

  1. Medium
  2. LinkedIn
  3. TopMate

Comments

Popular posts from this blog

5 Simple Changes in Power BI to Reduce Data Model Size by 99%🤩