Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
Hi All,
I recently migrated from enumerateObjectInstances to getFormattingModel() for defining custom formatting options in my Power BI custom visual. Everything is working fine, but I am facing an issue with conditional formatting:
Thanks in advance
Below is the relevant part of my code:
public getFormattingModel(): powerbi.visuals.FormattingModel {
// Ensure settings are initialized or use default settings
this.visualSettings = this.visualSettings || <VisualSettings>VisualSettings.getDefault();
// Create formatting cards based on the visualSettingsConfig
const cards: powerbi.visuals.FormattingCard[] = Object.keys(visualSettingsConfig).map((objectName) => {
const config = visualSettingsConfig[objectName];
const slices: any[] = Object.keys(config.properties).map((prop) => {
const controlType = this.getControlType(prop);
const isColorPicker = controlType === powerbi.visuals.FormattingComponent.ColorPicker;
// Fetch propertyInstanceKind for conditional formatting
const propertyInstanceKind = config.properties[prop].propertyInstanceKind;
const descriptor = {
objectName,
propertyName: prop,
...(propertyInstanceKind && { propertyInstanceKind }), // Include propertyInstanceKind if applicable
};
const control: any = {
type: controlType,
properties: {
descriptor,
value: isColorPicker
? { value: this.visualSettings[objectName][prop] }
: this.visualSettings[objectName][prop],
},
};
return {
uid: `${objectName}_${prop}_slice`,
displayName: config.properties[prop].displayName,
control,
};
});
return {
displayName: config.displayName || objectName.charAt(0).toUpperCase() + objectName.slice(1),
uid: `${objectName}_card`,
groups: [
{
displayName: "",
uid: `${objectName}_single_group`,
slices,
},
],
};
}).filter((card) => card !== null);
return { cards };
}
// Helper method to get the control type based on property type
private getControlType(propertyName: string): powerbi.visuals.FormattingComponent {
if (/\b(color|fill|solid|plan|gridfill)\b/i.test(propertyName)) {
return powerbi.visuals.FormattingComponent.ColorPicker;
} else if (/show|toggle/i.test(propertyName)) {
return powerbi.visuals.FormattingComponent.ToggleSwitch;
} else if (/size|width|height|fontsize|padding/i.test(propertyName)) {
return powerbi.visuals.FormattingComponent.NumUpDown;
} else if (/direction|secdirection/i.test(propertyName)) {
return powerbi.visuals.FormattingComponent.ConditionalFormattingControl; // Trying to enable conditional formatting
} else {
return powerbi.visuals.FormattingComponent.TextInput;
}
}
Hi @vamsi1997 ,
The issue with conditional formatting not working and the "fx" button missing in your Power BI custom visual is likely due to missing or incorrect propertyInstanceKind definitions. When migrating from enumerateObjectInstances to getFormattingModel(), conditional formatting must be explicitly enabled for relevant properties. To resolve this, ensure that propertyInstanceKind is set to powerbi.visuals.PropertyInstanceKind.ConditionalFormatting in the descriptor object. Additionally, verify that the getControlType() method correctly assigns ConditionalFormattingControl only to supported properties. In your formatting model, update the control definition to explicitly allow conditional formatting by adding allowConditionalFormatting: true where applicable. If the issue persists, check if Power BI supports conditional formatting for the selected property type, as some properties may not be eligible. These adjustments should ensure that the "fx" button appears in the formatting pane, allowing users to apply dynamic conditional formatting within your custom visual.
Passionate about leveraging data analytics to drive strategic decision-making and foster business growth.
Connect with me on LinkedIn: Rohit Kumar
Hi @vamsi1997 ,
What type of custom visual did you create?
Conditional formatting is not supported if the visual is table and matrix based.
Conditional formatting of Power BI custom visuals - Power BI | Microsoft Learn
Best Regards,
Dengliang Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
86 | |
81 | |
53 | |
37 | |
37 |