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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Custom Slicer sync across pages

Hello,

 

I'm creating a custom visual that will work as a slicer.

The basic idea is that I have another custom visual that let's user select an item and I want to propagate that selection to different pages (in fact, it doesn't have to be selection I just need information what item is selected there). I can't do that using a custom visual that allows for selection because it requires more than 1 data field which prevents me from directly using 'supportsSynchronizingFilterState'. So my idea is that there will be a slicer which, when it received only one item in the update method, will filter for that item only. This slicer will sync with other pages so that it affects only them. This way I would be able to propagate the selection of my custom visual through different pages.

The problem I encounter is that I'm unable to propagate those changes to other pages. In my testing, it correctly filters for the

page it is visible on, but other pages remain completely unaffected.

 

Thanks for any hints!

 

My capabilities (note: it doesn't support highlights, maybe that's a problem please confirm):

 

 

{
    "dataRoles": [
        {
            "displayName": "AnalysisId",
            "name": "analysisId",
            "kind": "Grouping"
        }
    ],
    "dataViewMappings": [
        {
            "conditions": [
                {
                    "analysisId": {
                        "min": 0,
                        "max": 1
                    }
                }
            ],
            "categorical": {
                "categories": {
                    "for": {
                        "in": "analysisId"
                    }
                }
            }
        }
    ],
    "objects": {
        "general": {
            "displayName": "General",
            "displayNameKey": "formattingGeneral",
            "properties": {
                "filter": {
                    "type": {
                        "filter": true
                    }
                }                         
            }
        }    
    },
    "suppressDefaultTitle": true,
    "supportsSynchronizingFilterState": true
}

 

And my code for applying filters, please note I don't do anything with regards to filtering and/or syncing in this slicer else and maybe it is required:

            private updateFilter(): void {
                this.clearAllDiscreteSelections();
                this.options.callbacksForFilter.removeFilter();
                // this.host.applyJsonFilter(undefined, "general", "filter", FilterAction.remove); 
                if(this.options.onlyRemove) {
                    return;
                }
                const target: IFilterColumnTarget = this.options.callbacksForFilter.getAdvancedFilterColumnTarget();
    
                let conditions: IAdvancedFilterCondition[] = [];
    
                const analysisId: string = this.options.analysisViewModel.analysisId;
                conditions.push({
                    operator: "Contains",
                    value:  analysisId
                });

                console.log(`Filtering to: ${analysisId}`);
                const filter: IAdvancedFilter = new window['powerbi-models'].AdvancedFilter(target, "And", conditions);
                this.options.callbacksForFilter.applyFilter(filter);
                // this.host.applyJsonFilter(filter, "general", "filter", FilterAction.merge);
            }

 

 

 

Sync slicers paneSync slicers pane

 

3 REPLIES 3
v-viig
Community Champion
Community Champion

Do you get a single element in the update method?

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

Anonymous
Not applicable

I figured it out.

 

For some reasons, I get 2 update methods to my slicer after selection (SelectionHandler.handleSelection(...)). One correctly contains only one element (the desired functionality), the second one, which immediately follows, contains all the elements in the data set. I simply made my selector ignore this second update because I have no idea where it comes from. I tested with Microsoft visuals, e.g. simple Table. When selecting an item I also get the same two updates.

 

@v-viig

Thanks for your information. Is the double update a known issue? Is there anything I can do to prevent it?

 Also what is the difference between applyJsonFilter and ISelectionManager.applySelectionFilter() and then ISelectionManager.select()? It's really confusing, not to mention ISelectionHandler.handleSelection in this mix...

v-viig
Community Champion
Community Champion

Not sure if this issue is expected. Can you share a Power BI Report to investigate and debug it?

 

applyJsonFilter is to apply a json (powerbi-models) filter to Power BI report. Other visuals will be filtered out.

The filter will be saved into Power BI hosted and restored when you opne the report again

 

ISelectionManager.select applies a slection to other visuals. Selection won't be saved into host.

 

ISelectionManager.applySelectionFilter() works in the same like applyJsonFilter but it uses ISelectionId to generate a filter.

 

I hope it's clear now.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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