Master measures are Qlik Sense measures saved for future re-use. This article provides a guide to creating and using segment colours when creating a master measure.

What are master measure segment colours

Segment colours are a way to colour your master measure different colours, depending on its value. For example, assume you are running a small blog. One of your goals is to have at least 1000 page views from organic visitors per month. Adding segment colours to your measure of organic page views would allow you to colour months falling below 1000 in red and above in green.

Note that master measure segment colours can be set as absolute figures or as percentages. At the time of writing, master measure segments cannot be made variable through the use of expressions.

How to create master measure segment colours

Master measure segment colours are created in the second tab of the master measure creation box.

  1. Toggle the segment colours feature on.
  2. You can choose a template theme if you like but this isn’t necessary as all options below can be changed.
  3. Specify whether your segment values are absolute or based on percentages. It’s toggled off in the screenshot, as we’re working with absolute values.
  4. Add the segments. We used a ‘basic’ template that divided our data into two segments. If we want to create more segments, we can click ‘Add limit.’ This will divide the data into three segments. Clicking again will add a fourth segment, and so on. You will see where the segment has been added as an additional circle toggle will appear below the colours. You can change each segment’s colour by clicking on the colour and selecting a new one from the library or entering a hex code.
  5. Set a value for each segment limit or remove it if it’s not needed. To set a specific limit’s value, click on the circle above the toggle and input the value. If this is more suitable, you can tick the ‘Gradient’ box to blend your colours from segment to segment.

How to use master measure segment colours

Once you create a measure that is coloured via segments, you must tell your visualisation to use those colours. By default, the measure will be coloured using default colours. Note that for some visualisations, you cannot use the segment colours.

To use master measure colours in a chart, go to: ‘Appearance’ > ‘Colors and legend’. Then switch the ‘Colours: Auto’ to off. Then, from the dropdown choose ‘By measure’. Make sure your measure is selected from the measures list and play around with the settings below to get it looking just right.

Working example: creating a three-segment, absolute value master measure colour

For this example, assume we are running a small blog. We are measuring the number of organic visitors to the blog and displaying it per month as a bar chart. There is a target of getting at least 1500 organic visits to the blog per month. We want to highlight any bars representing months below or equal to 750 in red, 750-1500 in yellow and above 1500 in green. The colours should gradually fade into each other using the gradient option.

Here is how we would set up the segment colours for the master measure and the results. Note that in the colours screenshot, the leftmost limit is set to 750, and the rightmost limit is set to 1500 (pictured).

Working example: creating a three-segment, percentage value master measure colour

An important note on how the percentage segmentation works. It identifies the biggest value in your visualisation, given your dimensions. Then, it highlights data based on your set limits relative to that value, which is taken as 100%. For example, you are showing a bar chart with the number of sales per month, and the month with the biggest sales is £1000. If you have a single limit of 50%, the colour yellow below this limit and green above this limit, any months where the sales are below £500 will be coloured yellow while sales above £500 will be coloured green. Your percentage limit cannot be set to below 0. Therefore, this feature is NOT suitable for colouring percentage change, as you might intuitively think. See ‘Working example: creating a five-segment, absolute value representing percentage change master measure colour’ below for guidance on how to do just that.

For this example, assume we are running a small blog. We are measuring the number of organic visitors to the blog and displaying it per month as a bar chart. The bars should be coloured as follows: the bars which represent organic visits in the top 10% as green, visits in the bottom 10% as red, and visits between the bottom and top 10% as yellow. We do not want the colours to fade into each other gradually.

Here is how we would set up the segment colours for the master measure and the results. Note that in the colours screenshot, the leftmost limit is set to 10%, and the rightmost limit is set to 90% (pictured).

Working example: creating a five-segment, absolute value representing percentage change master measure colour

For this example, assume we are running a small blog. We are measuring the percentage change between the current month and the previous month of earnings from adverts displayed on the blog. We want to show this per day. For the percentage change, we want to have five segments of colours, from bright red, where the change is low, to bright green, where it is high.

Here is how we would set up the segment colours for the master measure and the results.

The five segment limits, from left to right, are:

  1. -0.5, i.e. anything below negative 50% will be bright red
  2. 0, i.e. anything below 0 but above negative 50% will be pink
  3. 0.25, i.e. anything above 0 but below a 25% increase will be light green
  4. 0.5, i.e. anything with an increase between 25% and 50% will be a slightly brighter green
  5. 0.75, i.e. anything with an increase between 50% and 75% will be an even brighter green. By default, the last segment will colour anything above 75% with the brightest green

Limitations of master measure segment colours

Master measure segment colours can not be used in all visualisations

A master measure segment colour can’t be used in all the available visualisation types. For example, when using a measure in a ‘Table’ or a ‘Pivot Table’ you will not find the option to colour the background or text of cells based on the segment colours defined. Instead, you must specify the colours using a function in the ‘Background color expression’ or ‘Text color expression’ inputs. These can be found within the ‘Data’ section, underneath the measure you want to colour.

The segment limits defined are not variable

The limits of the segments you define are not variable. This means that once a user applies selections, the segments do not readjust. If you use the ‘Percentage’ format of a segment, the values falling within the percentages will adjust, however, the percentages themselves are fixed. For example, if you have an absolute value limit of 1000, it will remain 1000 regardless of what selections are made. Equally, if you have a percentage limit of 90%, when selections are made, the 90% value will adjust but you cannot change the limit to 80% etc. Note that for most applications, this is sufficient.

However, if you do need to vary those limits, the only way to do it is to use the ‘Background color expression’ or ‘Text color expression’ for cells in tables and ‘Appearance’ > ‘Colors and legend’ > ‘Custom colors’ > ‘By expression’ in a chart rather than colouring a measure using segments.