# Conditional Formatting with Transparency Hex Codes

One of the best ways to implement conditional formatting is using the Field value option in the Visualizations pane. There are numerous reasons why this conditional formatting method is better than many, and one of them is that you can use the transparency masks on hex codes which we will discuss today. You may watch the full video of this tutorial at the bottom of this blog.

## How to Make Conditional Formatting Transparent

The image above is the data set on home prices that weâ€™ll be working on today. We aim to make the bars on this Bar Chart transparent enough to see the map underneath.

If we go to the Format page in the Visualizations pane, you will see that thereâ€™s no transparency option for the bars. However, we can make any element with a conditional formatting option here transparent using field value and conditional formatting.

If we bump this slider up a little bit, it’ll show the hex code with two optional characters on the end, as shown in the image below. What those characters show is the percent opacity for the hex code.

The first six characters of the hex code (247ba0) represent the Coast Guard blue color, while the last two (80) represent the opacity. You can calculate the opacity by subtracting the percent transparency (20) from the 100, thus giving us 80.

## Numeric Parametic Slider

We first want to set the parameter using the numeric parameter slider and then adjust the color by harvesting the hex code from the table. Letâ€™s use Space Cadet blue for our color and set the transparency to zero.

Now, this action doesn’t let you see the map behind it. If we look at this CF Bar measure in DAX, we’ve harvested the hex code and the Percent Transparent Value, as highlighted in the image below.

We then used a simple SWITCH (TRUE) construct that says if the Percent Transparency is 0, we return the six-character hex code or PctTrans = 0, Hex. The 0 gives us a full opacity hex code.

Furthermore, we added that if the Percent Transparency is 100, we return the hex code with 00 opacity or PctTrans = 100, Hex & “00”. The 00 gives us a fully transparent hex code. The image below is what a fully transparent hex code looks like, and it makes all the visual vanish.

If we switch the True statement to everything in the middle and take the hex code to 100 minus the Percent Transparency or Hex & (100 â€“ PctTrans â€“ 100), we can make data labels more readable depending on selection. At 50 transparency or less, we are at the darker colors, as you can see in the image below

## Using the Dynamic Font Measure for Conditional Formatting

We are currently at the darker colors and want to use white for the data labels, so we’ll use the Dynamic font measure in the Field section.

It states that if the Percent Transparency is less than 50, we will use white. If it’s at a hundred, then we make it invisible; if it’s greater than 50, we use black.

You can see below that if we change our Percent Transparency and lighten up the bar color, it turns the data labels dark.

***** Related Links *****
Expression Builder: Applying Conditional Formatting On Paginated Reports
How To Control The Interactions Of Your Visuals In Power BI
Custom Conditional Formatting Techniques In Power BI

## Conclusion

Now you can set your transparency and color exactly how you want and use it in your Power BI visuals. Furthermore, you can allow the user to change hex codes for accessibility reasons and the like.

There are numerous other ways you can use conditional formatting in combination with DAX, transparency mask, and opacity numbers. The interesting thing about this method is that with either the gradient or the rule-based conditional formatting, you can only access it through the field value.

Brian Julius
Brian Julius has over 30 years experience in performing complex analysis of economic and business operations data. His interests include addressing DAX-related challenges and applying innovative techniques to improve the Power BI user experience.

## How To Merge Queries In Power BI

Merging is another powerful transformation to optimize our...

## Unpacking The Evolution Of Power BI – From Launch to Now

Microsoft Power BI is a dynamic business intelligence platform that has revolutionized the way...

## Finding Patterns In Your Data Using Internal Logic in Power BI

Today Iâ€™m going to showcase how you can discover patterns in your data when using Power BI. This is an...

## Report Builder Tutorial: Sort & Filter Data In Paginated Reports

In this Report Builder tutorial, youâ€™ll learn how to sort and filter the data in your paginated...

## Creating A Pareto Chart In Power BI – Advanced DAX

This blog tutorial showcases a really interesting example around Pareto analysis. Iâ€™m going to teach...

## Power BI Tooltips On Report Images

With the recent Power BI challenges that we run in Enterprise DNA, I've become a huge fan of the Power...

## Best Practices In Using The Q&A Feature In Power BI

The Q&A feature or the natural language feature is seriously one of the most incredible features...

## Perpetual Holiday Calendar – POTW #12 (Power Query Solution)

In this blog post, we'll explore my solution to Problem of the Week #12. For this challenge, we...

## What Is DAX Studio In Power BI Desktop

This tutorial will discuss what DAX Studio is and how it can be used to optimize your DAX codes. DAX...

## DAX Queries Using Variables And Important Functions

This tutorial will discuss about variables, including the FILTER and CALCULATE functions. Youâ€™ll...

## Dynamic Tooltip In Power BI With Embedded Charts

I want to show you an awesome trick for the visualizations in your reports. You can use a dynamic...

## Power Query Features: An Overview

This tutorial will discuss about the available features inside the Power Query Editor. You'll learn how...