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.

If you want to download the full script, just fill out your details below.

    Parameter sniffing solved with new Parameter Sensitive Plan Optimization feature

    If you’re someone that works a lot with Microsoft SQL Server, there’s no doubt that you’ve had issues with an issue called “Parameter sniffing” before. Up until now, you had...

    Creating maps with R and Power BI

    The possibilities are infinite when it comes to creating custom visuals in Power BI. As long as you have creativity and knowledge about the right programming language, you can let...

    Sending monitoring alerts through Telegram

    What if you could get the ease of phone notifications for whatever monitoring alerts you need? Then we have a solution for you with the app Telegram. Some of you...

    Send mails with Azure Elastic Database Jobs

    The DatabaseMail feature in SQL Server and Managed Instance is widely used by many professionals. But what if you want a similar functionality in Azure SQL Database? There are options,...

    Sorting matrices in Power BI

    Recently I worked on a Power BI project for a client. They had a SharePoint site where they regularly published articles and wanted to pour view data into a report...

    The world of data is evolving

    The data landscape has changed dramatically over recent years. In the past, we mainly heard that we needed to do as much as possible “cloud-only”—but this trend has become more...