Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

View all the Fabric Data Days sessions on demand. View schedule

Reply
matthias_vc
Frequent Visitor

Visual Format settings are reset after closing and opening

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.

1 REPLY 1
GrowthNatives
Solution Specialist
Solution Specialist

 

Hi @matthias_vc , i understand you got stuck with Visual Format settings reseting after closing and opening.

Let's see why it happens

Your visual resets to default because objects (the stored format settings in the DataView) aren’t being read correctly in getViewModel(). When Power BI reopens the file, it tries to restore settings from metadata.objects, but your code always falls back to defaultSettings.


Quick fix

  1. Read objects properly
    In update():

    const dataView = options.dataViews && options.dataViews[0];
    const objects = dataView?.metadata?.objects;
    let viewModel = this.getViewModel(options, objects);
    this.mstaSettings = viewModel.settings;

    Pass objects into getViewModel().

  2. Make sure names match capabilities.json
    Object names like 'lines' and property names like 'show' must match exactly (case-sensitive).

  3. Use correct selector
    In enumerateObjectInstances:

    selector: null

    This ensures settings are stored globally, not per-data-point.

  4. Don’t overwrite settings
    Don’t reassign this.mstaSettings to defaults anywhere after reading from the model.


To confirm it’s fixed

Change some visual settings → save PBIX → close → reopen.
If they persist, the issue’s resolved.

Essentially:
Ensure your visual reads metadata.objects, matches names from capabilities.json, and uses selector: null.
That’s what allows Power BI to restore formatting after reopening.

Hope this solution helps you make the most of Power BI! If it did, click 'Mark as Solution' to help others find the right answers.
💡Found it helpful? Show some love with kudos 👍 as your support keeps our community thriving!
🚀Let’s keep building smarter, data-driven solutions together!🚀 [Explore More]

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors