Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hello.
We have an utility that gets all the filter information of every visual using the standard #getFilters method. For some reason, we can't get the filters of one visual.
The filters applied to this visual have empty values (one advanced filter, one Top N filter) which hasn't been a problem on other visuals. No filter displays the warning icon that a filter is invalid.
When trying to track down the problem, we could reproduce it using the playground and this snippet of code:
try {
const pages = await report.getPages();
const page = pages.find(page => page.isActive);
const visuals = await page.getVisuals();
const visual = visuals.find(visual => visual.name === "<visual ID>");
console.log(await visual.getFilters());
}
catch (errors) {
console.log("Error", errors);
}
However, the error is just undefined.
When trying to debug further into Microsoft's code, it seems that there is an actual error but that it is mishandled, here is the stack:
{ "message": "Invoked filter serialization function with no filter.", "stack": "Error: Invoked filter serialization function with no filter. at De.ensureError (https://content.powerapps.com/resource/powerbiwfe/scripts/reportEmbed.min.b01b01905167f493a762.js:1:1458833) at De.throwException (https://content.powerapps.com/resource/powerbiwfe/scripts/reportEmbed.min.b01b01905167f493a762.js:1:1460336) at i.serializeFilter (https://content.powerapps.com/resource/powerbiwfe/scripts/reportEmbed.json-contracts.min.4dbb3fc597b1e8406319.js:1:7900) at I.fromSemanticFilter (https://content.powerapps.com/resource/powerbiwfe/scripts/reportEmbed.json-contracts.min.4dbb3fc597b1e8406319.js:1:6862) at https://content.powerapps.com/resource/powerbiwfe/scripts/reportEmbed.json-contracts.min.4dbb3fc597b1e8406319.js:1:29982 at Array.map (<anonymous>) at u.tryGetFilters (https://content.powerapps.com/resource/powerbiwfe/scripts/reportEmbed.json-contracts.min.4dbb3fc597b1e8406319.js:1:29970) at https://content.powerapps.com/resource/powerbiwfe/scripts/reportEmbed.filter.min.902d70a4ede44353ca9e.js:1:2916 at Generator.next (<anonymous>) at n (https://content.powerapps.com/resource/powerbiwfe/scripts/reportEmbed.vendors.min.b4e0d0f6f68362882eed.js:1:789804)" }
And this ends up being unused as the #getFilters method tries to get a body even when it isn't set, as can be seen here: https://github.com/microsoft/PowerBI-JavaScript/blob/master/src/visualDescriptor.ts#L108
So it seems that:
* There is a particular problem when serializing some filters
* When that happens we can't get an accurate error
Is there any possibility of at least seeing issue #1 fixed? We can provide a sample using email if necessary (sample has private data).
Thanks
Hey @sami_romdhana ,
You're hitting a known issue with the Power BI JavaScript SDK's getFilters() method when it tries to serialize certain filter types like Top N or Advanced filters with missing or undefined values. The internal method serializeFilter() throws: Error: Invoked filter serialization function with no filter.
This happens because some visuals contain a filter object with an undefined body, yet the SDK still attempts to serialize it and fails silently. Instead of catching and surfacing this error, the SDK mishandles it and returns undefined, which makes debugging almost impossible from the outside.
Before calling getFilters(), you could do a check for visuals using getFilters() inside a try-catch and skip if it returns undefined or logs that serialization issue.
try { const filters = await visual.getFilters(); if (!filters || filters.length === 0) { console.warn(`No filters found or failed for visual: ${visual.name}`); } else { console.log(filters); } } catch (e) { console.error(`Error retrieving filters for visual ${visual.name}`, e); }
This helps isolate the offending visual and possibly avoids full script breakage.
This won’t give visual-level granularity but may capture filters that failed serialization on visuals.
const pageFilters = await page.getFilters(); const reportFilters = await report.getFilters();
This way, you may at least infer what’s being filtered and whether it's likely a Top N/advanced filter scenario.
If you're able to modify the report:
Clear and recreate the problematic filter in Power BI Desktop.
Avoid incomplete Top N filters (e.g., without a full value definition).
Re-upload and test.
You're right the fix ideally belongs in PowerBI-JavaScript GitHub: visualDescriptor.ts#L108. There should be a:
if (!filter) { return []; // Or log detailed error }
For Detailed Information:
https://github.com/microsoft/PowerBI-JavaScript/blob/master/src/visualDescriptor.ts#L108
https://github.com/microsoft/PowerBI-JavaScript
https://learn.microsoft.com/javascript/api/overview/powerbi/visualdescriptor#getfilters
https://learn.microsoft.com/power-bi/developer/embedded/embed-sample-for-your-organization
https://github.com/microsoft/PowerBI-JavaScript/issues/new/choose
If you found this solution helpful, please consider accepting it and giving it a kudos (Like) it’s greatly appreciated and helps others find the solution more easily.
Best Regards,
Nasif Azam