Please note javascript is required for full website functionality.
MVP

Blog

Power BI Blog: Different Coloured Columns in a Chart

25 February 2021

Welcome back to this week’s edition of the Power BI blog series.  This week, Jonathan Liau will look at how to create different coloured columns in a column chart. 

 

Imagine that we have the following stacked column chart in Power BI: 

The chart displays the Dates on the x-axis and the SalesAmounts on the y-axis.  It looks good, it’s simple and it displays the historical and current sales (at time of writing 2021).  However, someone has requested that the current year’s column should be coloured differently.

There are several approaches to do this, but I think the quickest one in this scenario is to use DAX and write two separate measures.  The first measure I will create will calculate the historical sales amounts: 

Historical Sales =

CALCULATE(

    [Total Sales],

    CalendarTable[Year] < 2021

)

 

Now to write the Current Sales measure, which will use the following DAX code.  It is very similar to the Historical Sales measure, with a slight tweak in the condition.

Current Sales =

CALCULATE(

    [Total Sales],

    CalendarTable[Year] = 2021

)

 

Both measures require a calendar table of some sort (you can read more about calendar tables here). 

Plotting these two measures onto the same visualisation will yield the following result: 

This solution also works if we drill down to the quarterly level in the data: 

If we do not like blue, we can change the colours with the following steps.  With the visualisation selected, we can head on over to the Format panel, then click on the ‘Data colors’ option.  This will reveal an option to change the colour for each measure:

Here, we will be able to change the colours to a different combination. 

That’s it for this week!  This was a quick and simple way to colour different columns in your stacked columns charts in Power BI.  Join us next week for more on Power BI.

 

In the meantime, please remember we offer training in Power BI which you can find out more about here.  If you wish to catch up on past articles, you can find all of our past Power BI blogs here.  

Newsletter