Conditional Formatting (Fx) in PowerBI Custom Visual

Conditional Formatting (Fx) in PowerBI Custom Visual

Conditional Formatting (Fx) in PowerBI Custom Visual

👋 Hi Everyone 👋 During this time, I have a chance to implement the PowerBI Custom Visual with my team. And we spent a lot of time researching the conditional formatting (Fx) and we found many interesting things. I hope this blog can help everyone who interested to implement this feature in PBI Custom Visual.

Prerequisite:

  • In this blog, I create an example visual following this document. Please create an app follow this tutorial before going to the section below. Or you can clone an example visual from my repository.
  • Due, I use ReactJS to create a custom visual. So, you have to know about the basics of React too.

Let’s start !!

  1. Once you create or clone the ReactCircleCard visual, you should able to run & see like this screen.

ReactCircleCardVisual

  1. Next, open the package.json file and update the powerbi-visuals-api as 3.6.0 and add the powerbi-visuals-utils-dataviewutils as 2.4.1. Due to the conditional formatting feature is available in API v.3.6.0+

PackageJsonFile package.json file

  1. Next, update the “apiVersion” to 3.6.0 in pbiviz.json file.

PackageJsonFile pbiviz.json file

  1. Run npm install to update libraries in your node_module again.

  2. Then, import the code at the top of visual.ts file.

import { dataViewWildcard } from "powerbi-visuals-utils-dataviewutils";
import VisualEnumerationInstanceKinds = powerbi.VisualEnumerationInstanceKinds;
  1. Next, edit the enumerateObjectInstances method in visual.ts file like code below. At this point, we gonna use properties which come from capabilities.json file to show up the conditional formatting feature in fill property.

PackageJsonFile Edit the enumerateObjectInstances method to support the conditional formatting feature

At this step, you have to make sure all properties in capabilities.json are declared & bind this.setting parameter in the enumerateObjectInstance method.

  1. Add the visualTransform method that will parse a color value from DataView and bind the new value to this.setting. After that, call visualTransform method in update() & fix minor code like below.

VisualTransform

  1. When you refresh a custom visual in PowerBI report, you will able to see the conditional formatting feature in the color section.

PowerBIColor

  1. When you click on the FX button, it will popup the conditional formatting dialog and you can set the color scale based on the value field.

ConditionalFormatting

  1. If you add the color scale in conditional formatting, This value will appear in dataView object.

ColorRange DataView return the Color Range

  1. So, you can get code colors & values for Min/Max and apply this to your visual later.

Note: You can clone this project (with FX feature) via this link: https://github.com/iamkhwan/Tutorial-ReactCircleCard/tree/conditional-formatting


Limitations/Need to know in PowerBI API 3.6.0

  • As I tried to get the rule value from the conditional formatting, The Categorical data type only can able to get the value of the Rules in conditional formatting. (I attempted to get it in Single/Table/Matrix that don’t work)

  • Single/Table/Matrix can get only the color scale value like the example in this blog.

  • The conditional formatting feature can show in Field tab only. It can’t show up in the Fields tab like Matrix visual can do.

ConditionalFormatting2


Finally, you can show the conditional formatting feature in a custom visual app. I hope this content will help & guide you to develop your custom visuals. YAYYYYY

👋 See ya next times 👋


References:

Related Posts

Let's check our site's accessibility easily using 'Accessibility Insights for Web' on Microsoft Edge.

Let's check our site's accessibility easily using 'Accessibility Insights for Web' on Microsoft Edge.

Hello to all the readers who have come across this article. Lately, I've been quite busy and it's taken me a while to find some free time to write on Medium. Today, I want to share some knowledge tha

read more
Let's try to create Power Automate connected to SQL Server for sending Leave Approval Email using Low code together.

Let's try to create Power Automate connected to SQL Server for sending Leave Approval Email using Low code together.

Hello everyone! I've been away for a long time from blogging due to various events that have kept me busy, making it challenging to find time for writing. In my latest article, I briefly introduced P

read more
An Introduction to Microsoft's Power Automate

An Introduction to Microsoft's Power Automate

Today, we're introducing Microsoft's Power Automate, formerly known as Microsoft Flow. If you're familiar with Microsoft Power Platform services such as Dynamics 365, SharePoint, Power Apps, PowerBI,

read more
Pass Through Data Over IServiceProvider.CreateScope()

Pass Through Data Over IServiceProvider.CreateScope()

[ASP.NET] In some cases you may encounter the situation that you need to pass through some particular data over a new scope of Service Provider.For instance, when you implement a solution that inte

read more
Write Unit Tests for React Hooks using react-hooks-testing-library

Write Unit Tests for React Hooks using react-hooks-testing-library

Hooks in React are a feature that has drastically changed the way we write React. It's like undergoing plastic surgery in Korea, where some developers love the new look, while others prefer the old o

read more
Scan code with Credential Scanner on Azure DevOps

Scan code with Credential Scanner on Azure DevOps

🥳 Happy New Year 2023! 🥳Wishing everyone a great year ahead!Now, let's get down to business. Today, I'm going to introduce you to a handy tool that checks for leaked passwords, secrets, certifi

read more
Easy way to check user’s permission on SharePoint Online site in the web part

Easy way to check user’s permission on SharePoint Online site in the web part

Hello Everyone! 🎉 Happy New Year 2021 🎉 I hope you have a wonderful holiday, good vibes, and a nice party 🍻. This blog is the 2nd content which’s I write in English. In the previous blog, I explai

read more
SharePoint Group & Permission levels in SharePoint Online

SharePoint Group & Permission levels in SharePoint Online

Hello everyone 👋 !!! This is the 1st time that I wrote the SharePoint Online blog in English. This blog explains permission levels in SharePoint Online. Once you create a new site in SharePoint Onli

read more
Speed up and make your SPFx reloads quick and easy with the SPFx-Fast-Serve tool.

Speed up and make your SPFx reloads quick and easy with the SPFx-Fast-Serve tool.

Hello everyone! I'm back! In the past period, I've been busy expanding my knowledge, reading some Microsoft Learning materials, trying out new things, and handling various tasks, which left me with l

read more
What is SharePoint? How does it work? Let's take a look together! 😆

What is SharePoint? How does it work? Let's take a look together! 😆

Hello everyone who stumbled upon and is reading this content. After spending a considerable time exploring various content on Medium, I wanted to share a little bit of my knowledge. Having delved int

read more