Forum Discussion

DavidAnthony's avatar
DavidAnthony
Icon for Helper II rankHelper II
1 year ago
Solved

How to Apply a Filter to a Specific Power BI Custom Visual Without Affecting Other Visuals?

Hi everyone,
I'm working on a Power BI custom visual and trying to implement a filter that only applies to my specific visual, without affecting other visuals on the same page. Below is the code I'm currently using to apply the filter:
 
const dataTarget = [{ table , column }];
const dataValues = [value];

try {
  let filter = {
    $schema: "https://powerbi.com/product/schema#tuple",
    filterType: 6,
    operator: "In",
    target: dataTarget,
    values: dataValues,
  };

  host.applyJsonFilter(
    filter,
    "general",
    "filter",
    powerbi.FilterAction.merge
  );
} catch (error) {
  console.error("Filter error:", error);
}
The issue is that when I apply this filter using host.applyJsonFilter, it affects all visuals on the page that share the same data source, not just my custom visual. I want the filter to be isolated to my visual only.
How can I modify my code or approach to ensure the filter only impacts my custom visual, leaving other visuals on the page unaffected? Any advice or examples would be greatly appreciated!
Thanks
  • Hi DavidAnthony ,

    Thank you for reaching out to Microsoft Community.

    Try local filtering inside your visual logic, where it filters data post dataView load, you must handle the filtering inside your visual logic, not through applyJsonFilter.

    While building the visual, apply your own filtering logic to the dataView before rendering.

    Refer this document for implementing Data view: Power BI Custom Visual Part 4 - Accessing the DataView - Shetland Data

    If this post helps, please give us Kudos and consider marking it Accept as solution to assist other members in finding it more easily.

    Regards,
    Chaithra.

     

5 Replies

  • v-echaithra's avatar
    v-echaithra
    Icon for Community Support rankCommunity Support

    Hi DavidAnthony ,

    Thank you for reaching out to Microsoft Community.

    Try local filtering inside your visual logic, where it filters data post dataView load, you must handle the filtering inside your visual logic, not through applyJsonFilter.

    While building the visual, apply your own filtering logic to the dataView before rendering.

    Refer this document for implementing Data view: Power BI Custom Visual Part 4 - Accessing the DataView - Shetland Data

    If this post helps, please give us Kudos and consider marking it Accept as solution to assist other members in finding it more easily.

    Regards,
    Chaithra.

     

  • v-echaithra's avatar
    v-echaithra
    Icon for Community Support rankCommunity Support

    Hi DavidAnthony ,

    As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?
    If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

     

    Regards,
    Chaithra.

  • v-echaithra's avatar
    v-echaithra
    Icon for Community Support rankCommunity Support

    Hi DavidAnthony ,

    We wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?
    If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

     

    Regards,
    Chaithra.

  • v-echaithra's avatar
    v-echaithra
    Icon for Community Support rankCommunity Support

    Hi DavidAnthony ,

    As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?
    If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

     

    Regards,
    Chaithra.