The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now
Power BI already gives us a way of applying conditional formatting on the table and matrix visuals using the default settings.
Suppose I need to give some custom color-based formatting to my cells in a table visual, how will I achieve this?
There is an easy way to create custom color formattings in Power BI using a simple measure calculation. In this article I will walk you through a step-by-step example on how to implement this in Power BI.
Let us consider the following table visual:
I have got sales by clothing category, by day of a week in the above table visual.
Now, my task is to give a custom conditional formatting to the Day of Week column above based on the Clothing Category.
For example - Clothing Category = Jackets should be GREEN
Clothing Category = Jeans should be BLUE
Clothing Category = Pants should be AMBER
Clothing Category = Shirts should be RED
In order to give a custom color coding, I will create a simple DAX measure to achieve this:
The above DAX is a simple SWITCH statement, that gives a custom color based on the clothing categories.
Colors are represented using COLOR HEX CODES.
Now, let us see how we can use this custom measure to give our table a conditional formatting.
Click on the table visual --> go to Formatting options --> Conditional Formatting --> Background Color --> ON
Once you do this a new window appears with default background color options.
Now we need to modify this setting to use the custom measure that we created to get the background color working as we want. See below:
Now in the above window, I have selected following options:
Once you click OK in the above window, you end up with following:
Voila! We have given conditional formatting to Day of Week column based on the clothing Category value.
I just tried to add a simple legend on the top to represent the color coding.
So, this is how one can use a custom color formatting in Power BI by creating a simple measure for it.
Hope this article helps everyone out there.
- Pragati
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.