How to Utilize Color Palette Function in PBRS for Stunning Visualization

by | Mar 11, 2020 | ConfigMgr, How-To, SQL Server Reporting Services, Tips | 3 comments

Last updated on December 31st, 2023 at 11:27 am

I’m updating my blog post to create a color palette for Ask Garth logo. So, I thought that I would show you the Power BI Report Server (PBRS/PBIRS) or SQL Server Reporting Services (SSRS) function that I use. This function will allow me to apply a defined color palette to reports and allow me to synchronize colors between Charts and tables/matrix.

If you have ever written any reports for SSRS or Power BI (either desktop or report server). You know that when you create a chart and table a random color is automatically assigned. This is fine if you don’t want any control over what colors are used. Or don’t care what the end result looks like. So how can you sync the colors between the two objects?

In all of Ask Garth reports, however, I never (rarely) use the automatically assigned colors. Instead, I set the colors myself at least use branded colors. In this blog post, I show you one of the color palette codes we use at Ask Garth. Then I explain what each part of the code means.


This is as hard one to explain but PBRS reports created with VS will actually be SSRS reports. And they can be used on either SSRS or PBRS. In PBRS they will show up within the paginated Section within the folder. So even though I use PBRS thru this blog, everything applies to SSRS too.


There are many reasons you would want to define the colors used in a SSRS report. These include: making the information easier to read (e.g. matching the colors between a chart and a table), following style guides or adhering to Web Content Accessibility Guidelines (WCAG). We use our own custom color palettes to help customers understand data more quickly and easily.

I have written a number of blog posts on why color is important. But here is a good one to start with, How Color Is Used in Power BI and SSRS Dashboards.


Here’s an example of a color palette code and function that we use at Ask Garth:

Private colorPalette As String() = {"#F25430","#404959","#D5C72B","#9C4D1F",

Private count As Integer = 0
Private mapping As New System.Collections.Hashtable()

Public Function GetColor(ByVal groupingValue As String) As String
	If mapping.ContainsKey(groupingValue) Then
		Return mapping(groupingValue)
	End If
	Dim c As String = colorPalette(count Mod colorPalette.Length)
	count = count + 1
	mapping.Add(groupingValue, c)
	Return c
End Function


In order to create your own color palette code, you need to understand what is needed. I know when you first look at the code above. It is a bit of an eyechart, so let me break it down for you.

colorPalette is defined as an array of strings. Each string is a color, so each one forms part of my color palette.

Do no mix and match color name and color codes. In my opinion, this is a bad move because colour (UK spelling intended) names change based on what country you live in. You can read more about that in, When is Grey Not a Valid Color?. Which is also why I highly recommend that you use Hex Color codes exclusively. This is to ensure that you always get the correct color.

Next, there is a variable called, “count As Integer.” What the name is self-explanatory.

After that, “mapping” is defined as a “shortcut” to the System.Collections.Hashtable API function.

Now for the “meat and potatoes” of the code. The Ask Garth function, GetColor, at a high-level, accepts a string and then checks to see if there is already a defined color for that string. When one already exists, the color code is returned. Else the next color code on the list is returned.

In the code above, the first color returned is #F25430 and then #404959, etc. When the end of the color palette is reached (52 colors to be exact in this example). The function starts over at the beginning with #F25430.

The function is using simple math to define the color code.


Now that I explained the basics of a color palette code, you can get to work!

Need help creating a color palette? Please read, How to Create a Color Palette for Your ConfigMgr Reports Once you decide what colors you want to use. You can simply edit each string in the code above by swapping out the HEX color code with your own choice.

Obviously, you can adapt the function for any number of predetermined instances. I plan to publish a blog post in the not-too-distant future that shows you how to modify the function.

Lastly, you need to add your color palette code to a report.


Report Properties Menu

From the menu, Extension then select Report and then click on Report Properties…

GetColor function listed Code node for the RDL. Select the Code node and then paste the code with your color palette into the Custom code area. Click on the OK button.

With that last step completed, you are now ready to use your color palette! In next week’s “Unleashing the Power of GetColor Advanced Techniques for PBRS Chart Customization”, you’ll see how to assign this color palette code to a chart. The following week, Tips for Perfectly Matching Colors in Your RDL Chart and Table.

How to Utilize Color Palette Function in PBRS for Stunning Visualization Video

Follow along with me as I show you the steps that I took to add the GetColor function to RDL.

If you have any questions about How to Utilize Color Palette Function in PBRS for Stunning Visualization Video? Please also subscribe to my YouTube channel and newsletter to stay on top of the latest trips and tricks. Additionally, if you have any questions, please feel free to touch base @Garthmj.