Select Page

In this post, you will learn how to create your own theme in Power BI Desktop.

If you think themes in Power BI are just about “pretty colors”, you are dead wrong. A solid custom theme is a powerful tool to bring consistency across all reports. It will save you from spending hours in changing colors or fonts individually for each visual. Most importantly, it will prevent behaviours that lead to dangerous errors in self-service reports (e.g. a user duplicating an entire report page just to keep the same “Look & Feel”, not realizing that page-level filters are also duplicated and affect the visuals made on the duplicate page – NOT FUN!). Okay enough with the boring part – now let’s get to the good stuff!

Context

Let’s say you just made a report page with a couple of visualizations: bar charts, line charts and so on. We’ll use this report for illustration. You’ve used the handy “format pane” to have your visuals the way you like: added a legend on one, added titles for the X & Y axes on another. Great. But what happens when your colleague wants to add pages to the report? He’ll discover that the visuals added do not look like yours. He might use the “Format Painter”, but it’ll get cumbersome if lots of visuals need to be adapted. And if the report is lost, all formatting properties are lost as well… Let’s take that report & make a custom theme to prevent all this from happening.

Pick a Theme and Export it

A custom theme is simply a JSON file that Power BI uses to apply visual properties to the report. We start by picking a theme in the “View” tab from the tob ribbon. I’ve picked one of the themes available from the list offered in the drop-down menu. Since colors were all set as “Default” (no custom colors picked from the format pane), I see some changes immediately in my report.

Once we have selected a theme, we can export it from the same drop-down menu. We get a small JSON that has some HEX codes of the theme we’ve picked, and not much else for now.

Customize Your Theme

We head to the Options menu to enable the preview feature “Customize Current Theme”. It’s only available since December 2019, so make sure you have the latest version of Power BI.

Once this is done, we head over to “Customize Current Theme” in the themes menu. We can do some customization from this window: adding a border to all visuals, setting a background color for the filter pane and changing the default color for the titles.

Although creating or customizing a theme with the new visual interface from Power BI is a great start, editing the JSON is much more powerful and convenient if we use the right tools & resources. If we export the theme after saving our changes, we notice that the JSON has gotten bigger and contains the changes we’ve just made. Now we simply use an online tool to format our JSON properly (I use https://jsonformatter.org/). And a proper text editor is crucial – I use Brackets because it displays the colors of each HEX code when I hover over one, which is handy!

,We are not far from our end goal here, which is to define the default visual properties of the report at two levels: (1) those that apply to all types of visuals, and (2) those to apply to some visuals only. Take a closer look at the JSON file:

(1) Under the first “*” are the properties that apply to all visuals. In our case, we see the border property that we defined in the visual editor.

(2) Under “visualStyles” we can find define the properties for all types of visuals separately. Each element has its own name. For instance, the filter pane is called “outspacePane” here. I strongly suggest you to use this page on GitHub to find out sample code for each visual. The documentation from Microsoft is also worth a look but can be confusing. For custom visuals, I can only wish you good luck. Their name can be a very random, such as the names for the Hierarchy Slicer and Advance Card (check out this community post to find out).

Watch out… each time we edit the JSON, we need to save the file and re-import it in the report (“Import Theme” or “Browse For Themes…” in the “View” tab). I find it best to work side-by-side with the format pane of the visual you are editing, so that you do not lose track of what properties you are working on. Although some properties can be guessed, it can be tricky to find the correct name. And the JSON file is case-sensitive, so having a capital letter where it shouldn’t can “break” the theme, causing an error message when trying to import the JSON into Power BI. The same goes for syntax errors, so start small and proceed carefuly.

 

Wrapping up

I hope this post has helped you better understand how themes can be beneficial for you and how to start making your own. If you have any question or remark, please feel free to reach out. I will leave you with some links that are worth your time:

Edouard Clément

Data Analyst