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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
MartijnBre
Frequent Visitor

Custom visual and filtering?

I am trying to apply a filter from my custom visual to the whole report. For some reason it gives me the refresh (so it looks like it is filtering), but actually it is not filtering.

 

The capabilities.json look like this:

{
    "dataRoles": [
        {
            "name": "Index",
            "kind": "Grouping",
            "displayName": "Index"
        },
        {
            "displayName": "Text",
            "name": "text",
            "kind": "Grouping"
        }
    ],
    "dataViewMappings": [
        {
            "table": {
                "rows": {
                    "select": [
                        {
                            "for": { "in": "Index" }
                        },
                        {
                            "for": { "in": "text" }
                        }
                    ]
                }
            }
        }
    ],
     "objects": {
        "general": {
            "displayName": "General",
            "properties": {
                "formatString": {
                    "displayName": "Format String",
                    "type": { "text": true }
                }
            }
        }
    }
}
 
The way I am trying to filter (now it is hard coded):
 
const filter: IBasicFilter = {
            $schema: "http://powerbi.com/product/schema#basic",
            target: {
                table: "Reviews",
                column: "Index"
            },
            operator: "In",
            values: [1, 2, 3],
            filterType: 1
        };
   
        document.getElementById('search').onclick = (event) => {
            if (this.host) {
                console.log("apply")
                this.host.applyJsonFilter(
                    filter,
                    "Reviews",
                    "Index",
                    powerbi.FilterAction.merge
                );
            } else {
                console.error("Host not available.");
            }
        }
 
Does anyone know if I am doing something obviously wrong?
1 ACCEPTED SOLUTION
dm-p
Super User
Super User

Hi @MartijnBre,

 

With the detail provided, things almost look OK but your capabilities aren't set up for filtering. You have the dynamic format string functionality available, but you should have your general object at least set up as follows to tell Power BI that your visual is permitted to filter the data model:

 

 

{
    ...
    "objects": {
        "general": {
            "displayName": "General",
            "properties": {
                "filter": {
                    "type": {
                        "filter": true
                    }
                }
            }
        },
        ...
    }
    ...
}

 

 

Regarding your code, consider the table name, column name and values are present in your model. If not, then Power BI may not apply the filter, as it will determine it not to be a valid query and will save resources.

 

One final tweak: your applyJsonFilter call should be as follows, based on the above capabilites configuration:

 

 

    this.host.applyJsonFilter(
      filter,
      "general",
      "filter",
      powerbi.FilterAction.merge
    );

 

 

Note parameters 2 and 3 refer to object name and property name (which is where Power BI should persist the filter in your visual capabilities), not table and column name (these are already in the filter criteria).

 

I made these changes in a brand new visual and the filter worked as expected. Hopefully, this is all you need to get moving again.

 

Good luck!

 

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




View solution in original post

2 REPLIES 2
dm-p
Super User
Super User

Hi @MartijnBre,

 

With the detail provided, things almost look OK but your capabilities aren't set up for filtering. You have the dynamic format string functionality available, but you should have your general object at least set up as follows to tell Power BI that your visual is permitted to filter the data model:

 

 

{
    ...
    "objects": {
        "general": {
            "displayName": "General",
            "properties": {
                "filter": {
                    "type": {
                        "filter": true
                    }
                }
            }
        },
        ...
    }
    ...
}

 

 

Regarding your code, consider the table name, column name and values are present in your model. If not, then Power BI may not apply the filter, as it will determine it not to be a valid query and will save resources.

 

One final tweak: your applyJsonFilter call should be as follows, based on the above capabilites configuration:

 

 

    this.host.applyJsonFilter(
      filter,
      "general",
      "filter",
      powerbi.FilterAction.merge
    );

 

 

Note parameters 2 and 3 refer to object name and property name (which is where Power BI should persist the filter in your visual capabilities), not table and column name (these are already in the filter criteria).

 

I made these changes in a brand new visual and the filter worked as expected. Hopefully, this is all you need to get moving again.

 

Good luck!

 

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Amazing, thanks a lot for the help! Works like a charm now.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.

Top Solution Authors