kohera-logo-regular.svg

How to Automatically add measures to Power BI

Some time ago I wrote a blogpost to retrieve all the measures from your tabular cube or from your open Power BI files. I want to make a simple addition to this blog, more specifically one that unravels a technique that can be used to automate some actions in Power BI, like the creation of measures. The trick is actually pretty simple, but for some reason I just didn’t try it before.

Watch the How To video on this topic:

With this simple PowerShell code, we’re adding nine (fixed) measures to an open Power BI file (the first table is used to store the measures, but you can also provide the name of the table between “double quotes”):

The last line saves the changes to the model behind the Power BI file, but does not show the measures straightaway. So, the trick is to refresh the Power BI data after running the script (you could also explicitly save the Power BI file). Your measures should then become visible!
This is the full code (you need to have one – and only one – open Power BI file with at least one table):

After running the script, we go from this:

To this (after a refresh on the ‘Products’ table):

Now it’s up to you to get creative. I only used fixed measures, so you could just copy and paste the script without adapting it to your model. For some (I hope many) Power BI developers, this will speed up their development process.

I still do hope a real API will see the daylight in the near future.

Group of computer programmers working in the office. Focus is on blond woman showing something to her colleague on PC.
Updating your Azure SQL server OAuth2 credentials in Power BI via PowerShell for automation purposes
The better way to update OAuth2 credentials in Power BI is by automating the process of updating Azure SQL Server...
2401-under-memory-pressure-featured-image
Under (memory) pressure
A few weeks ago, a client asked me if they were experiencing memory pressure and how they could monitor it...
2402-fabric-lakehouse-featured-image
Managing files from other devices in a Fabric Lakehouse using the Python Azure SDK
In this blogpost, you’ll see how to manage files in OneLake programmatically using the Python Azure SDK. Very little coding...
2319-blog-database-specific-security-featured-image
Database specific security in SQL Server
There are many different ways to secure your database. In this blog post we will give most of them a...
kohera-2312-blog-sql-server-level-security-featured-image
SQL Server security made easy on the server level
In this blog, we’re going to look at the options we have for server level security. In SQL Server we...
blog-security_1
Microsoft SQL Server history
Since its inception in 1989, Microsoft SQL Server is a critical component of many organizations' data infrastructure. As data has...