Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi, I've made a Custom visual that Looks quite ok and has about 60 Format settings that a user can vary depending on their preference.
It all worked perfectly untill I saved a PBI file with this visual and opened it up again. All the settings were back to default. Any ideas on what I did wrong?
below is the general scheme of how my code looks like related to the settings:
...
interface Viewmodel {
...
settings: MSTASettings;
}
interface MSTASettings {
lines: {
show: boolean;
...
}
...
}
let defaultSettings: MSTASettings = {
lines: {
show: true,
...
}
...
}
export class Visual implements IVisual {
constructor(options: VisualConstructorOptions) {
this.mstaSettings = <MSTASettings>{};
...
}
public enumerateObjectInstances(options: EnumerateVisualObjectInstancesOptions): VisualObjectInstanceEnumeration {
let objectEnumeration: VisualObjectInstance[] = [];
switch (options.objectName) {
case 'lines':
objectEnumeration.push({
objectName: objectName,
properties: {
show: this.mstaSettings.lines.show,
...
},
selector: {}
});
break;
...
return objectEnumeration
}
public update(options: VisualUpdateOptions) {
let viewModel = this.getViewModel(options);
let settings = this.mstaSettings = viewModel.settings;
...
}
private getViewModel(options: VisualUpdateOptions): Viewmodel {
let viewmodel: Viewmodel = {
...
settings:<MSTASettings>{},
...
};
viewmodel.settings = {
lines: {
show: getValue<boolean>(objects, 'lines', 'show', defaultSettings.lines.show),
...
},
...
}
...
return viewmodel;
}
function getValue<T>(objects: DataViewObjects, objectName: string, propertyName: string, defaultValue: T): T {
if (objects) {
let object = objects[objectName];
if (object) {
let property: T = <T>object[propertyName];
if (property !== undefined) {
return property;
}
}
}
return defaultValue;
}
}
Note: I didn't use the latest version as I started this project a couple of years ago and only now found the time to tweek it.
Note2: I tried getting rid of the line In the Constructor. My code still worked, but the issue remained the same.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
78 | |
78 | |
58 | |
35 | |
32 |
User | Count |
---|---|
99 | |
59 | |
56 | |
46 | |
40 |