Reputation: 1
I'm facing the below issue when using the PowerBI-JavaScript library to set filters on a visual:
I'm unable to set the following types of filters: Advanced (filterType: 0) and TopN (filterType: 5) on a visual when using the setFilters
function (on the visual object), for example:
const myAdvancedFilter = {
$schema: 'http://powerbi.com/product/schema#advanced',
target: {
table: 'MyDataTable',
measure: 'TimeDifference'
},
filterType: 0,
logicalOperator: 'And',
conditions: [
{
operator: 'GreaterThanOrEqual',
value: 0
},
{
operator: 'LessThanOrEqual',
value: 12
}
]
}
myVisual.setFilters([myAdvancedFilter])
.catch(errors => {
console.log(errors) // An error occurs
});
This is the error that I receive:
The following also doesn't work:
reportPage.getVisuals().then(visuals => {
let firstVisual = visuals[0]; // Note: The report only contains one visual
firstVisual.getFilters().then(visualFilters => {
// The visualFilters array contains advanced/topN filters (note: the visual has the advanced filters applied when it is initially embedded; before I attempt to set filters)
firstVisual.setFilters(visualFilters).catch(errors => {
// If I attempt to set the 'visualFilters' to the visual I get the error depicted in the above screenshot. This issue shouldn't occur because the report already has these filters applied
});
})
})
The setFilters()
function appears to send a PUT
request (/report/pages/{PageName}visuals/{Visual}/filters) to the embedded report (in the iframe) passing the filters in the request body. The response is returning the 'InvalidFilter' error.
Note: I'm able to set basic filters e.g. a value on a column without any errors. For example:
const basicFilter = {
$schema: 'http://powerbi.com/product/schema#advanced',
filterType: 1,
operator: 'In',
target: {
table: 'MyDataTable',
column: 'Zone'
},
values: ['MyZone']
}
myVisual.setFilters([basicFilter])
.catch(errors => {
console.log(errors) // No error occurs
});
I'm able to set all filters (basic, advanced and topN) via the filter pane, I'm just unable to set them programmatically via the PowerBI-JavaScript library.
How do I solve this problem?
Upvotes: 0
Views: 423
Reputation: 101
The syntax and implementation looks correct as I validated from my end and as per the documentation of constructing filters. This kind of error is thrown if the table or column name reference provided is incorrect.
May be one or more of the referenced entities (table, column) in the filter definition is no more available in the report, or the name is not correct.In this case, the "Invalid filter definition" error will be thrown while setting the filters.
Upvotes: 2