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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
murphycrosby
Regular Visitor

Need to add a Format Property per Measure

For each Measure in the dataset, I need to add a format property.  I've allowed multiple measures in the capabilities.json file, but I actually want an AxisObject per measure.  Therefore, I'd like the format to be Axis_1 with a Property 1 and a Property 2, then an Axis_2 with a Property 1 and a Property 2.  This way I can group them by measure rather than the alternative of grouping them by Property.

 

Here is my current Capabilities and enumerateObjectInstances (right now I'm just looping statically 2 times to try and get it to work).  I've tried different selector types with no luck.

 
    "objects": {
        "axisObject" : {
            "displayName": "Axis",
            "properties": {
                "property1": {
                    "displayName": "Property 1",
                    "type": {
                        "bool": true
                    }
                },
                "property2": {
                    "displayName": "Property 2",
                    "type": {
                        "bool": true
                    }
                }
            }
        }

 
switch( objectName ) {
    case 'axisObject':
        for(let i = 0; i < 2; i++) {
            objectEnumeration.push({
                objectName: objectName,
                displayName: objectName + "_" + i,
                properties: {
                    property1: this.settings.axisObject.property1,
                    property2: this.settings.axisObject.property2
                },
                    selector: null
            });
        }
        break;
};
 
4 REPLIES 4
murphycrosby
Regular Visitor

The only way I can get it to work the way I want, is to hard code them in the capabilities, and then don't push them on the 

objectEnumeration array unless the categorical value length is long enough.  However, that seems like a hack.
 
"objects": {
	"yaxisObject1": {
		"displayName": "Y-Axis 1",
		"properties": {
			"property1": {
				"displayName": "Property 1",
				"type": {
					"bool": true
				}
			},
			"property2": {
				"displayName": "Property 2",
				"type": {
					"bool": true
				}
			}
		}
	},
	"yaxisObject2": {
		"displayName": "Y-Axis 2",
		"properties": {
			"property1": {
				"displayName": "Property 1",
				"type": {
					"bool": true
				}
			},
			"property2": {
				"displayName": "Property 2",
				"type": {
					"bool": true
				}
			}
		}
	},
	"yaxisObject3": {
		"displayName": "Y-Axis 3",
		"properties": {
			"property1": {
				"displayName": "Property 1",
				"type": {
					"bool": true
				}
			},
			"property2": {
				"displayName": "Property 2",
				"type": {
					"bool": true
				}
			}
		}
	}
}
public enumerateObjectInstances(options: EnumerateVisualObjectInstancesOptions): VisualObjectInstance[] | VisualObjectInstanceEnumerationObject {
	console.log('enumerateObjectInstances', this.dataView);
	let objectName: string = options.objectName;
	let objectEnumeration: VisualObjectInstance[] = [];

	switch( objectName ) {
		case 'yaxisObject1':
			if(this.dataView.categorical.values.length > 0) {
				objectEnumeration.push({
					objectName: objectName,
					properties: {
						property1: this.settings.yaxisObject1.property1,
						property2: this.settings.yaxisObject1.property2
					},
					selector: null
				});
			}
			break;
		case 'yaxisObject2':
			if(this.dataView.categorical.values.length > 1) {
				objectEnumeration.push({
					objectName: objectName,
					properties: {
						property1: this.settings.yaxisObject2.property1,
						property2: this.settings.yaxisObject2.property2
					},
					selector: null
				});
			}
			break;
		case 'yaxisObject3':
		if(this.dataView.categorical.values.length > 2) {
				objectEnumeration.push({
					objectName: objectName,
					properties: {
						property1: this.settings.yaxisObject3.property1,
						property2: this.settings.yaxisObject3.property2
					},
					selector: null
				});
			}
			break;
	};

	return objectEnumeration;
	//return VisualSettings.enumerateObjectInstances(this.settings || VisualSettings.getDefault(), options);
}

It seems you should specify a selector for each instance of VisualObjectInstance.

To find out more please take a look at this example.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

That example only seems to show adding properties dynamically to a group.  I'm needing to dynamically add additional groups of properties.

 

Currently, I've defined 5 of the same groups of properties then just don't push them if I don't have a measure for it.  This makes my capabilities longer than it needs to be, and caps my number of measures to the number of properties defined in the capabilities.

We would recommend to return an instance of VisualObjectInstanceEnumerationObject as a result of enumerateObjectInstances.

This interface describes containers and instances. To associate an instance with a particular container you would need to fill containerIdx of VisualObjectInstance.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Kudoed Authors