Forum Discussion
Power BI Embedded: Problem using more than one filter on the same Embedded exporting all the Visuals
- 4 years ago
Hi, we solved it it was the [] characters when sending the filter.
I attach the solution!! Thanks!
function ReplaceFilters() {
//var a = $("#In1").val();
//var b = $("#In2").val();
const filterList = [{
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "tCalendarioNestleN",
column: "SemanaNestle"
},
logicalOperator: "And",
conditions: [{
operator: "GreaterThanOrEqual",
value: 1
}, {
operator: "LessThanOrEqual",
value: 5
}]
},
{
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "tProductos",
column: "cveCategoria"
},
operator: "In",
values: ["PURINA"]
}];var embedContainerPortafolio = $('#TendenciaSOut')[0];
var reportPortafolio = powerbi.get(embedContainerPortafolio); // Replace all report's filters.try {
reportPortafolio.setFilters( filterList);
// reportPortafolio.setFilters([filterList]); this was the one you sent us.
} catch (errors) {
console.log(errors);
}
/* catch (errors) { console.log(errors); }*/
}
HI Hugo_Gallardo,
I found you define multiple functions with filter structures to apply filters effect to your report, so I recommend you to transform them into one const variable and use it to set/update filters.
function ReplaceFilters() {
var a = $("#In1").val();
var b = $("#In2").val();
const filterList = [{
$schema: "http: //powerbi.com/product/schema#basic",
target: {
table: "tCalendarioNestleN",
column: "SemanaNestle"
},
logicalOperator: "And",
conditions: [
{
operator: "GreaterThanOrEqual",
value: a
},
{
operator: "LessThanOrEqual",
value: b
}
]
}, {
$schema: "http: //powerbi.com/product/schema#basic",
target: {
table: "tProductos",
column: "cveCategoria"
},
operator: "In",
values: ["SP"]
}];
var embedContainerPortafolio = $('#ChartFR')[0];
var reportPortafolio = powerbi.get(embedContainerPortafolio);
// Replace all report's filters.
try {
reportPortafolio.updateFilters(models.FiltersOperations.ReplaceAll, [filterList]);
} catch (errors) {
console.log(errors);
}
}
Power BI Playground - Developer Sandbox
Regards,
Xiaoxin Sheng
Ok last update, we changed the code as follows but only does the last filter, but it shows us the kind of json it expects in the following image. Do we need to change the json?
const filterList = ([{
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "tCalendarioNestleN",
column: "SemanaNestle"
}
logicalOperator: "And",
conditions: [{
operator: "GreaterThanOrEqual",
value: 1
}, {
operator: "LessThanOrEqual",
value: 5
}]
},
{
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "tProductos",
column: "cveCategoria"
},
operator: "In",
values: ["PURINA"]
}]);
var embedContainerPortafolio = $('#TendenciaSOut')[0];
var reportPortafolio = powerbi.get(embedContainerPortafolio); // Replace all report's filters.
try {
reportPortafolio.setFilters([filterList]);
} catch (errors) {
console.log(errors);
}
/* catch (errors) { console.log(errors); }*/