What is a Power Query Template and why is it a big deal in the era of Fabric?

What is a Power Query Template and why is it a big deal in the era of Fabric?

If you are in the data analytics realm, Microsoft Fabric has been all over the place in the previous months! Fabric introduced “this”, Fabric implemented “that”, “this” integrates seamlessly with Fabric, and so on…New features and functionalities are being incorporated almost on a daily basis, and it’s really hard to stay up to date with all the innovations and improvements.

In this “ocean” of innovations, there are certain features that don’t get the deserved limelight – as they somehow go under the radar. I really consider some of them “hidden gems” – you might not use them in each and every solution, but in some scenarios, they can be of immense help.

I’m introducing today a hidden gem called Power Query Template. As of today, this feature is still in preview (the same as many others in Microsoft Fabric), but this doesn’t minimize its potential.

What is a Power Query Template?

When you work with your data in Power Query (and I assume you all opened Power Query Editor at least once, since you are reading Power BI – related blog:)), you define a lot of different things there: for example, queries, parameters, locale settings, etc. Now, imagine being able to pack all of these into one single box, and then being able to reuse the content of that box somewhere else! That’s exactly what Power Query Template enables you to do.


How can I create a Power Query Template from Power Query Desktop?

Well, I have bad news – you can’t:(…Power Query Template can be generated only from the Power Query Online experience – meaning you can only leverage Dataflows (Gen1) to create a template. But, stay tuned, I’ll show you how to create Power Query Template from the existing Power BI semantic models with some Python (sempy) magic…

Create a template from Dataflow Gen1

If you are not sure what Dataflow Gen1 is, don’t worry – I get you covered . Once you open a dataflow, you’ll see the option to Export template:


Once you provide a name for your template, it will be saved as a .pqt file. To leverage the template data in Fabric, you need a Fabric capacity and Fabric-enabled workspace.

The item you need is a Dataflow Gen2, which is one of many options for ingesting the data into Fabric. Once you create a new Dataflow Gen2, you should see the option to Import from a Power Query Template:

From there, the process is fairly straightforward and once you locate your .pqt file, you’ll see that “everything” is in there – all your transformations, settings, and queries! On top of that, since we are now in Fabric and using a Dataflow Gen2, we can output the data into various destinations, such as lakehouse or warehouse. How cool is that!

Once you publish the Dataflow, it will create a Delta table in the destination (let’s imagine that our destination is a Fabric lakehouse) and from there, anyone who has access to a lakehouse can leverage the data from that Delta table. So, instead of being “caged” in the Dataflow, where only Power BI can consume the data from it, now any downstream workload can potentially benefit from having this data available – you can query it by using SQL, Spark, use it for data science or machine learning tasks, and so on.

This is cool, but let’s be honest—the number of use cases is fairly limited. The data is not always stored in Dataflow Gen1, and it would be great if we could also create Delta tables out of “regular” Power Query stuff performed in Power BI Desktop and stored in the Power BI semantic model in the workspace.

This time, I have good news:) This is feasible thanks to SemPy library in Python and great work from Michael Kovalsky who provided the script for implementing this approach.

Create Power Query Template from existing Power BI semantic models

If you’re not familiar with Michael Kovalsky ‘s work, you are missing a lot:) Michael maintains a fantastic GitHub repo, full of super-useful scripts and solutions. In case you missed it, I already described how to migrate existing Power BI import models to Direct Lake . Here, I just want to show how you can create Delta tables from tables in the existing Power BI model – meaning, you don’t necessarily need to use Direct Lake mode on top of them (you can if you want, of course), but have them available in Delta format within Fabric, so that essentially any Fabric engine can take advantage of them.

The entire process is described within in the Semantic Link Labs GitHub Repo , so I’ll focus only on the key steps to bring your Power BI imported tables into OneLake.

The first step is to install the library in Fabric notebook:

%pip install semantic-link-labs        

Next, install the necessary libraries:

import sempy_labs as labs
from sempy_labs import migration, directlake
from sempy_labs import lakehouse as lake
from sempy_labs import report as rep
from sempy_labs.tom import connect_semantic_model        

Now, we are ready to create a .pqt file:

create_pqt_file(
            dataset = 'PQT Demo',
            file_name = 'PQT Demo pqt',
            workspace = None
            )        

Let’s go now to the Files section of our lakehouse and check if the file is there…


As you may notice, the file was successfully created. The next step is to use Dataflow Gen2 in the same way as we did previously when importing data from Dataflow Gen1.


All my transformation logic applied via Power Query Editor in Power BI Desktop is preserved, so my newly created delta tables in the lakehouse are just “plug-and-play” – I don’t need to repeat the same transformation steps and apply my transformation logic from scratch.

I’ll configure the output destination for my tables and publish the Dataflow. After a few minutes, tables that were part of the import semantic model, with all their transformation logic, are now available in the Fabric lakehouse in delta format.


Conclusion

Power Query Template is a very useful feature. Although this definitely should not be your default choice when moving data into Fabric, there are certain scenarios in which your transformation logic already took place in the Power BI semantic model and/or Dataflows Gen1, and reusing this logic makes more sense than recreating everything from scratch.

Thanks for reading!

Luis Eduardo P.

SAP Analytics Consultant

2 个月

Interesting

Alex Dean

Turning Data into Value. Client Partner @Unit8, Helping customers grow sustainably by unleashing the power of their data

2 个月

Curreny this is also the only way to do any kind of devops with Gen 2 Dataflows. Once Gen2 Dataflows are fully git compatible then this hidden gem will diminish in brightness.

要查看或添加评论,请登录

Nikola Ilic的更多文章

社区洞察

其他会员也浏览了