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
ilgialla
New Member

Power BI playground: get visual filters

Hi everyone,

 

I cannot been able to get visual filters from the "Sample Report" example on https://microsoft.github.io/PowerBI-JavaScript/demo/v2-demo/index.html

 

For example, i filtered for "Manufacturer" field selecting only "Barba" value, then i tried the given code:

 

// Get a reference to the embedded report HTML element
var embedContainer = $('#embedContainer')[0];
 
// Get a reference to the embedded report.
report = powerbi.get(embedContainer);
 
// Retrieve the page collection and get the visuals for the first page.
try {
    const pages = await report.getPages();
 
    // Retrieve active page.
    var activePage = pages.filter(function (page) {
        return page.isActive
    })[0];
 
    const visuals = await activePage.getVisuals();
 
    // Retrieve the target visual.
    var visual = visuals.filter(function (visual) {
        return visual.name == "VisualContainer4";
    })[0];
 
    const filters = await visual.getFilters();
    Log.log(filters);
}
catch (errors) {
    Log.log(errors);
}
 
and got this JSON as response:
 
> Json Object
[
{
"$schema": "http://powerbi.com/product/schema#basic",
"target": {
"table": "Product",
"column": "Category"
},
"filterType": 1,
"displaySettings": {
"isHiddenInViewMode": false
},
"operator": "All",
"values": [],
"requireSingleSelection": false
},
{
"$schema": "http://powerbi.com/product/schema#basic",
"target": {
"table": "Product",
"column": "Product"
},
"filterType": 1,
"displaySettings": {
"isHiddenInViewMode": false
},
"operator": "All",
"values": [],
"requireSingleSelection": false
},
{
"$schema": "http://powerbi.com/product/schema#basic",
"target": {
"table": "SalesFact",
"measure": "@Indicator01"
},
"filterType": 1,
"displaySettings": {
"isHiddenInViewMode": false
},
"operator": "All",
"values": [],
"requireSingleSelection": false
},
{
"$schema": "http://powerbi.com/product/schema#basic",
"target": {
"table": "SalesFact",
"measure": "#Space02"
},
"filterType": 1,
"displaySettings": {
"isHiddenInViewMode": false
},
"operator": "All",
"values": [],
"requireSingleSelection": false
},
{
"$schema": "http://powerbi.com/product/schema#basic",
"filterType": 1,
"displaySettings": {
"isHiddenInViewMode": false
},
"operator": "All",
"values": [],
"requireSingleSelection": false
},
{
"$schema": "http://powerbi.com/product/schema#basic",
"target": {
"table": "SalesFact",
"measure": "#Space01"
},
"filterType": 1,
"displaySettings": {
"isHiddenInViewMode": false
},
"operator": "All",
"values": [],
"requireSingleSelection": false
},
{
"$schema": "http://powerbi.com/product/schema#basic",
"target": {
"table": "SalesFact",
"measure": "@Indicator02"
},
"filterType": 1,
"displaySettings": {
"isHiddenInViewMode": false
},
"operator": "All",
"values": [],
"requireSingleSelection": false
},
{
"$schema": "http://powerbi.com/product/schema#basic",
"target": {
"table": "Date",
"column": "Running Year"
},
"filterType": 1,
"operator": "In",
"values": [
1
],
"requireSingleSelection": false
},
{
"$schema": "http://powerbi.com/product/schema#basic",
"target": {
"table": "Product",
"column": "Segment"
},
"filterType": 1,
"operator": "In",
"values": [
"Convenience",
"Moderation"
],
"requireSingleSelection": false
},
{
"$schema": "http://powerbi.com/product/schema#advanced",
"target": {
"table": "SalesFact",
"measure": "Total Category Volume"
},
"filterType": 0,
"logicalOperator": "And",
"conditions": [
{
"operator": "IsNotBlank"
}
]
}
]
 
why i can't see the filter i made?
 
Thank you
2 REPLIES 2
V-lianl-msft
Community Support
Community Support

As wiki i tried to get visual filters value and i'm correctly got them but i cannot see filter's actual selection value.

 

Using this code:

 

async filter() {
		if (!!this.embed) {
			let report = this.embed;
			let pages = await report.getPages();

			// Retrieve the active page.
			let activePage = pages.filter(function (page) {
				return page.isActive
			})[0];

			let visuals = await activePage.getVisuals();
			visuals.forEach((visual, i) => {
				visual.getFilters().then(filters => {
					console.log('visual ' + i, visual);
					console.log('filters', filters);
				});
			});
		}
	}

 

i'm getting this logs:

2021-04-13 17_07_34-https___localhost_44346_PowerBI_reportTag=AssetAllocation&idSgr=6&mode=read.png

 

as you can see i cannot get filtered value "Consumer staples" in the following donut chart: 

 

2021-04-13 17_13_11-https___localhost_44346_PowerBI_reportTag=AssetAllocation&idSgr=6&mode=read.png

 

 

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.