Callum

Callum Green's Blog

Themes in Power BI – Part 2

In September’s Power BI Desktop release, one of Microsoft’s announcements was a new offering of Themes.  My previous blog back in March 2017 explained what a Theme could (or couldn’t!) do, but I am pleased to say Microsoft listened to the community and have improved it greatly.

Originally, we were limited to setting a few page or chart colours - mainly tables and matrices.  Appreciated this was a first release from Microsoft, but it’s safe to say I was left uninspired.  The good news is Themes can now do a lot more, including:

-          Set the font size for specific charts e.g. 14

-          Set visuals to use a specific font type style e.g. Calibri

-          Turn off/on chart data labels

-          Set default property values for a chart

-          “*” functionality that will apply a specific property across all charts

This blog will focus on how to not only use the new features, but how they can be brought together to form a larger, organizational configuration file.

If you would like to follow my examples, please ensure you have downloaded the latest version of Power BI Desktop – found here.

New JSON

In order to extend the Adatis Theme, a new section called visualStyles must be added to the JSON.  The format is as follows:

clip_image001

The highlighted JSON sections give you the ability to use ‘*’ syntax, which means the Theme format will apply to everything underneath it.  This is useful for things if you want to apply a global font size across the entire report, rather than needing to configure every chart/visual.

Now, let’s pick a simple use case.  Client A requires the following to always be applied to a Pie Chart in Power BI Desktop:

-          Switch on the Pie Chart Legend

-          Set Text Size to 14

-          Set Font Family to Calibri Light.

Default Pie Chart:

clip_image003

-          By design, Legends are turned off.

The configuration file is tweaked to contain the new JSON - highlighted in yellow.

{

  "name": "Adatis",

  "dataColors": [ "#002C5C", "#006FBA", "#81C341", "#F4AA00", "#003876", "#00448F", "#0051A9", "#007ED4", "#008DED", "#74B238", "#8EC954", "#DB9800", "#FFB60F" ],

  "background": "#FFFFFF",

  "foreground": "#002C5C",

  "tableAccent": "#81C341",

  "visualStyles": {

    "pieChart": {

      "*": {

        "legend": [

          {

            "show": true,

            "fontSize": 14,

            "fontFamily": "Calibri Light"

          }

        ]

      }

    }

  }

}

The final step is to import the modified JSON file, resulting in a completely different looking Pie Chart. 

Applied Theme:

clip_image005

1.       The traditional Adatis chart colours have been applied.

2.       A Legend is visible – in both the properties pane and the visual itself.

3.       Font family and Text Size are updated.

Adatis Theme Extended

I will now add some additional configurations to the Adatis Themes file.

-          Turn On all Chart Legends.

-          Pie Chart Label Style set to Percent of Total.

-          Set Card Label and Category Label Font Size to 12, but all other visuals use 10.

This changes the JSON code significantly, but by following the visualStyles format, this was more straightforward than it seems.

{

  "name": "Adatis",

  "dataColors": [ "#002C5C", "#006FBA", "#81C341", "#F4AA00", "#003876", "#00448F", "#0051A9", "#007ED4", "#008DED", "#74B238", "#8EC954", "#DB9800", "#FFB60F" ],

  "background": "#FFFFFF",

  "foreground": "#002C5C",

  "tableAccent": "#81C341",

  "visualStyles": {

    "*": {

      "*": {

        "*": [

          {

            "fontSize": 10,

            "fontFamily":  "Calibri"

          }

        ],

         "legend":[{

                    "show":true

                }]

      }

    },

    "card": {

      "*": {

        "labels": [

          {

            "fontSize": 12

          }

        ],

        "categoryLabels": [

          {

            "fontSize": 12

          }

        ]

      }

    },

        "pieChart": {

          "*": {

            "labels": [

              {

                "labelStyle": "Percent of total"

              }

            ]

          }

     }

  }

}

The report is significantly different.  I will pinpoint a specific area of the report to illustrate where the configurations occurred.

Before:

clip_image007

After:

clip_image009

1.       Global font size is set to 10.

2.       Percent of Total setting applied to Pie Charts.

3.       Category Labels and Labels set to font size 12 for all Cards.

What else can Themes do?

This article is only scratching the surface at what Power BI Themes can now do.  Click here to find the extensive list of properties that can be configured.  It is worth mentioning that if you have limited JSON experience, some of the configurables can be a little tricky to set up.  However, there are quite a few blogs out there that can get anyone up to speed, which I will further provide below. 

Limitations

There are a couple of limitations, as well some things I have experienced:

-          Debugging JSON (natively within Power BI) is not supported and a syntax error occurs. Power BI will give you a generic error message like below:

clip_image011

-          Data configurations are not supported

·         This is understandable, though.  Every report tab contains different slices or filtering of data, but colours, fonts and chart properties tend to remain the same.

-          Setting Card font and background colours does not appear to be possible yet.  Or at least I have been unable to get it to work or find any supporting documentation from Microsoft to suggest it is.

-          Overriding a Theme

·         Individually changing a chart property will override the Theme JSON file.  I was caught out by this and couldn’t understand why the configuration wouldn’t change on a Pie Chart.

·         To get around this, use Revert to default within a chart property and it will re-apply the Theme.  This option exists in each top-level chart property – see example below.

clip_image013

 

Further Reading

o   Jason Lengstorf’s JSON Blog –  http://bit.ly/2aU1OHS

o   Power BI Desktop September Update - http://bit.ly/2y1QLWe

o   Power BI Report Themes BI Blog - http://bit.ly/2mPq69l

o   Themes Gallery (containing example JSON files) - http://bit.ly/2pyUKpl

Contact Me

If you would like a copy of the PBIX workbook/JSON Theme file or have any general questions, feel free to leave a comment below.  I am particularly interested to see what Theme files other people have created and if there any other known limitations.   

Twitter:                @DataVizWhizz

Themes in Power BI

Microsoft recently released Themes to a Preview version of Power BI.  The concept is pretty simple – imagine having standardized colours that can be applied to charts and matrix visuals? This is where Themes come in. The theory is this will ensure Power BI developers adhere to company policies and can do so quickly and efficiently. The reality is Themes are still lacking a lot of key configurables, but I will get onto that later.

Whilst this blog is not going to show you how to import or apply a Theme, it will demonstrate how to create one and what each configuration means. For a great high level walkthrough of the feature, click here. The aim is to not only show how this makes a developers life easier, but where it can actually be improved too.

JSON Configuration File

I have pasted the following code into Notepad++, which incorporates the Adatis branding and colour scheme.  For many developers, you will recognize the coding language – JSON (JavaScript Object Notation). If you would like to know more about JSON, check out Jason Lengstorf’s blog.

Use the below code as a template for your Theme:

{

  "name": "Adatis",

  "dataColors": [ "#002C5C", "#006FBA", "#81C341", "#F4AA00", "#003876", "#00448F", "#0051A9", "#007ED4","#008DED","#74B238","#8EC954","#DB9800","#FFB60F" ],

  "background": "#FFFFFF",

  "foreground": "#002C5C",

  "tableAccent": "#81C341"

}

Notice there are a number of ‘#’ within the code.  These are Hex numbers, in which Power BI natively uses to determine a shade of colour.  This is common across many reporting/image editing tools. 

Configurations Explained

I will now explain what each line of code means and how it will effect a simple un-themed report.

 

clip_image001

1.       The name of the Theme.

2.       The colours that appear in a pre-set chart colour palette and the order of which a visual applies them e.g. Dark Blue first, Light Blue second, Green third, etc.

3.       Font colour for the matrix or table visual.

4.       Primary background colour for a matrix or table visual.  Even though the setting says’ ‘foreground’, it is more of a background colour!

5.       The table accent applies to a matrix or table visual, displaying as the grid outline or contrasting background colour, depending on what type matrix/table is applied.

 

Applying a Theme

I have created a quick Power BI report, which is using the default colour schemes applied.  The only formatting applied was to the Matrix visual and this was simply changing the style of the grid.  Here is how the report currently looks:

clip_image003

Now let’s import and apply the ‘Adatis’ theme.  You will see some of the visuals have changed, whereas other elements of the report haven’t.  I will explain in greater detail.

clip_image005

1.       The Report Title, Slicers and Titles are not affected by the Adatis theme.  This is because you cannot currently configure fonts in the JSON file.

2.       The matrix visual has updated, using the three configurations form the JSON file:

a.       background (White)

b.      foreground (Navy Blue)

c.       tableAccent (Green)

3.       The Pie and Bar chart have picked up the colours in the order they are specified in the JSON file, using the dataColors property.  However, note the colour of both data points on the Bar Chart – rather than use different colours, it uses the same primary blue colour.  Not ideal if you want to plot one colour for ‘Male’ and another for ‘Female’.

4.       The Waterfall chart hasn’t changed at all.  We would expect the Adatis colours to have been applied, but this visual seems to ignore the configuration.

We can change the Waterfall Chart manually, using the imported Adatis Colour Palette. 

clip_image007

Here is how the chart now looks:

clip_image009

What’s Next?

Whilst the concept of Themes is great, the current preview functionality is extremely limited and very much ‘Version 1’.  I am a little disappointed with how inconsistent the application of a theme is, which were highlighted in my points above.

With the majority of new Power BI features, Microsoft continue to improve the usability and functionality over time, so I am very hopeful more Theme properties will be opened up in the underlying JSON configuration file.  Options such as font colours/styles, consistent theme application (for all visuals) and company logos are all necessary for this to become really powerful.  There were talks of a CSS type of configuration in Power BI, but this has yet to announced or released.  Imagine how powerful and cool that would be?

As a BI Consultant, I am not currently comfortable with demoing Themes to a client, simply because of the clear gaps.  Once the feature is more mature and in GA, I think enterprise companies will really benefit from standardising reports across their business.  For now, Themes will remain a glorified colour palette.

Further Reading

o   Jason Lengstorf’s JSON Blog –  http://bit.ly/2aU1OHS

o   Power BI Report Themes BI Blog - http://bit.ly/2mPq69l

Contact Me

If you would like a copy of the workbook or have any questions about this blog, please leave a comment below.

Twitter:                                @DataVizWhizz