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
Abrandhaug
Regular Visitor

Confused about slicers, filters and what API's to use

I'll try to explain my issue as best as I can. I'm mainly a developer and have just started trying to embed a report as per requested. 

I'm trying to change som filters (or slicers) on load. But I'm not sure what I need to do in order to achieve this. 
I've been messing around in the PBI playground for 2 days without getting any closer to achieve my goal. 

 

 

Im trying to change these filters in the drop down uplon load. I want to manipulate which checkboxes are checked upon load.

Abrandhaug_0-1664953254397.png

(red line is company Name)

In powerBI I see it is structured as a Filter: 

 

Abrandhaug_1-1664953341698.png

Where it looks like RegionName is the attribute I want to filter on. 
When I console.log active filters in the PBI playground I see the following: 

Abrandhaug_2-1664953478060.png

So I know the column and table

 

I've tried adding/replacing filter with this schema: 

const filter = {
target: {
table: "manageunit_dim_companyhierarchy",
column: "RegionName"
},
operator: "In",
values: ["Energi"]
};

 

 

With no luck. I've also tried to apply it as a hierarchy-slicer as per docs: 
https://learn.microsoft.com/en-us/javascript/api/overview/powerbi/control-report-slicers#hierarchy-s...

Which I also am not getting to work. 


Can anyone clarify what I'm doing wrong here? Or at least give me a pinpoint to what API i need to use? I'm confused wether I will achieve said goal with basic filter or if I need to use slicer. I hope my issue was clear. Thank alot! 

3 REPLIES 3
v-shex-msft
Community Support
Community Support

HI @Abrandhaug,

What type of effect did you want? Did you mean to set the filter with static items?
If that is the case, I'd like to suggest you use the bookmark to save the filter effect, then you can enable this to restore the saved filter effects.

Enhance your users' experience with bookmarks in Power BI embedded analytics | Microsoft Learn

If you mean dynamic change items after report load, I think you needed to manually define the filter structure and use update filter API to update these filter items.

Use filters when embedding a report in Power BI embedded analytics | Microsoft Learn

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi, yes - I want to set the filter with static items(The RegionName filter) before the report loads in my web-application. The idea is to manipulate the filter based on who's viewing the report in the web application. I want this effect to be applied before the report loads. 

Still looks to me like I need to use the API: Control report filters 

 

When I console.log visual filters - I find the filter I want to manipulate: 

 

Abrandhaug_0-1665039585040.png

this is the same filter as I see in the report: 

Abrandhaug_2-1665040207804.pngAbrandhaug_3-1665040257225.png

 

 


I want to target this filter and change so that the checkboxes on the left side menu is not selected as the report loads. 

 

I want to load the report with only one of the checkboxes selected. 

If I try to set filters like this before the report loads. Nothing happens - and I'm confused what I'm doing wrong here.

 

 

const basicFilter = {
  $schema: "http://powerbi.com/product/schema#basic",
  target: {
    table: "manageunit_dim_companyhierarchy",
    column: "RegionName"
  },
  operator: "NotIn",
  values: ["Energi", "Region Oslo", "Regioner Norge"],
  filterType: models.FilterType.BasicFilter,
  requireSingleSelection: false
}

 

 

I've also tried manipulating the checkboxes with this filter with no luck: 

const filter = {
"$schema": "http://powerbi.com/product/schema#hierarchy",
"target": [
{
"table": "manageunit_dim_companyhierarchy",
"column": "CompanyName"
},
 
{
"table": "manageunit_dim_companyhierarchy",
"column": "RegionName"
}
],
"filterType": 9,
"hierarchyData": [
{
"operator": "Inherited",
"value": "CompanyName AS",
"children": [
{
"operator": "NotSelected",
"value": "Energi",
}
]
 
}
]
};

 

HI @Abrandhaug,

I'd like to suggest you enable the RLS with username in power bi embedded, then these records can be filtered automate based on the user name. (you only need to modify the report to map the field you want to filter with the username)

Using row-level security with embedded content in Power BI embedded analytics - Power BI | Microsoft...

Solved: RLS with UserName() - Microsoft Power BI Community

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.