Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
Is there any custom visual which has this settings and source code for reference ?
or how to create this by code in the format panel ?
Thanks
Hi
Short answer: yesโuse the Formatting Model API and enable conditional formatting (the โFxโ button) on a color property by setting the propertyโs instanceKind to ConstantOrRule, and wiring selectors correctly. Microsoftโs Sample Bar Chart shows this pattern, and the docs walk through it step-by-step.
capabilities.json โ define a fill property (only color supports Fx)
{
"objects": {
"colorSelector": {
"displayName": "Data colors",
"properties": {
"fill": { "type": { "fill": { "solid": { "color": true } } } }
}
}
}
}
getFormattingModel โ surface a ColorPicker that supports Fx
import powerbi from "powerbi-visuals-api";
import * as dataViewWildcard from "powerbi-visuals-utils-dataviewutils";
public getFormattingModel(): powerbi.visuals.FormattingModel {
const card: powerbi.visuals.FormattingCard = {
displayName: "Data colors",
uid: "dataColorsCard",
groups: [{ displayName: undefined, uid: "dataColorsGroup", slices: [] }]
};
this.barDataPoints.forEach((p, i) => {
(card.groups[0] as powerbi.visuals.FormattingGroup).slices.push({
uid: `color${i}`,
displayName: p.category, // label in the pane
control: {
type: powerbi.visuals.FormattingComponent.ColorPicker,
properties: {
descriptor: {
objectName: "colorSelector",
propertyName: "fill",
// Fx needs a wildcard selector + an alt selector per point:
selector: dataViewWildcard.createDataViewWildcardSelector(
dataViewWildcard.DataViewWildcardMatchingOption.InstancesAndTotals
),
altConstantValueSelector: p.selectionId.getSelector(),
// <- enables the Fx button next to the color swatch
instanceKind: powerbi.VisualEnumerationInstanceKinds.ConstantOrRule
},
value: { value: p.color } // default color when no rule is set
}
}
});
});
return { cards: [card] };
}
This is the same pattern shown in Microsoftโs โAdd conditional formattingโ article and the SampleBarChart tutorial. Microsoft LearnGitHub
Reading the chosen color/rule
If the user picks a constant color, youโll get it back as usual via your formatting settings service or enumerateObjectInstances. If they set an Fx rule, Power BI evaluates it and your visual receives the computed color in the data view/objects for the matching data point (or via your settings service), so you just apply fill when drawing bars. Community and docs note that the wildcard/alt selectors are what bind rules to instances. Microsoft LearnStack Overflow
Useful references (source + docs):
Docs: Add conditional formatting (Fx) to custom visuals (includes code using instanceKind and selectors). Microsoft Learn
Sample code: PowerBI-visuals-sampleBarChart โ Tutorial/ConditionalFormatting.md and barChart.ts. GitHub
Library: powerbi-visuals-utils-formattingmodel (recommended for the new Format pane). GitHubMicrosoft Learn+1
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!