cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
vanillaicecream Regular Visitor
Regular Visitor

Apply JSON Filter not working

So I have been following the steps that were outlined here https://microsoft.github.io/PowerBI-visuals/docs/concepts/filter-api/#basic-filter-api

 

I created a basic filter: 

 

 

let target: IFilterColumnTarget = {
            table: "DataTable",
            column: "Category1"
        };
let values = [ 123 ];
let filter: BasicFilter = new BasicFilter(target"NotIn"
this.visualHost.applyJsonFilter(filter"general""filter"FilterAction.merge);
 
 
in my capabilities, I have added as specified:
 
 
"general": {
            "displayName""General",
            "displayNameKey""formattingGeneral",
            "properties": {
                "filter": {
                    "type": {
                        "filter"true
                    }
                }
            }
        }   
 
 
I know that my json filter is being applied. But for some reason the dataview that I receive doesn't change at all. Can anyone help?
 
 
1 ACCEPTED SOLUTION

Accepted Solutions
vanillaicecream Regular Visitor
Regular Visitor

Re: Apply JSON Filter not working

Yep, I've realised now thanks. 

 

It turns out the answer was simply to use

 

visualhost.applyJsonFilter(advancedFilter, "general", "selfFilter", FilterAction.merge);

 

instead of 

 

visualhost.applyJsonFilter(advancedFilter, "general", "Filter", FilterAction.merge);

 

This will filter the visual and not all the other visuals. 

View solution in original post

7 REPLIES 7
jppp
MVP

Re: Apply JSON Filter not working

Hi @vanillaicecream ,

 

this.visualHost.applyJsonFilter() pushes the filter back to Power BI so that all other visuals on the page are filtered by the content of the filter. It doesn't filter the data that the visual is getting; slicer are using the same technique.

 

-JP

vanillaicecream Regular Visitor
Regular Visitor

Re: Apply JSON Filter not working

Yep, I've realised now thanks. 

 

It turns out the answer was simply to use

 

visualhost.applyJsonFilter(advancedFilter, "general", "selfFilter", FilterAction.merge);

 

instead of 

 

visualhost.applyJsonFilter(advancedFilter, "general", "Filter", FilterAction.merge);

 

This will filter the visual and not all the other visuals. 

View solution in original post

onealmodovar Regular Visitor
Regular Visitor

Re: Apply JSON Filter not working

Hello.

 

Can you please share your current repository project?

 

Right now I'm facing an issue with FilterAction.merge

host.applyJsonFilter(models.AdvancedFilter, "general", "selfFilter", FilterAction.merge);
 
Cannot find name 'FilterAction'.
 
Thank You.

@vanillaicecream wrote:

Yep, I've realised now thanks. 

 

It turns out the answer was simply to use

 

visualhost.applyJsonFilter(advancedFilter, "general", "selfFilter", FilterAction.merge);

 

instead of 

 

visualhost.applyJsonFilter(advancedFilter, "general", "Filter", FilterAction.merge);

 

This will filter the visual and not all the other visuals. 



@vanillaicecream wrote:

Yep, I've realised now thanks. 

 

It turns out the answer was simply to use

 

visualhost.applyJsonFilter(advancedFilter, "general", "selfFilter", FilterAction.merge);

 

instead of 

 

visualhost.applyJsonFilter(advancedFilter, "general", "Filter", FilterAction.merge);

 

This will filter the visual and not all the other visuals. 




Highlighted
vanillaicecream Regular Visitor
Regular Visitor

Re: Apply JSON Filter not working

You need to add this to the top to import FilterAction

 

import FilterAction = powerbi.FilterAction;
 
lucmax Frequent Visitor
Frequent Visitor

Re: Apply JSON Filter not working

Hey @vanillaicecream ,

 

I'm trying to achieve exactly the behaviour and have my custom visual filter itself. I can't get your solution to work, did you do any other changes regarding for example the capabilities?

 

regards,

lucmax

vanillaicecream Regular Visitor
Regular Visitor

Re: Apply JSON Filter not working

Hey lucmax,

 

So you need to add selfFilter to your general capabilities too. Like this. So instead of filter, replace with selfFilter.  There is no documentation for this, so it was a lot of trial and error. 

 

"selfFilter": {
               "type": {
                  "filter": {
                     "selfFilter"true
                  }
               }
            }
lucmax Frequent Visitor
Frequent Visitor

Re: Apply JSON Filter not working

Thank you @vanillaicecream! That helped a lot. I tried changing them, but didn't do it with the double "selfFilter" key.

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

January 2020 Community Highlights

January 2020 Community Highlights

Make sure you didn't miss any of the things that happened in the community in January!

Top Solution Authors
Top Kudoed Authors