Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
nckpedersen
Helper I
Helper I

Guaranteeing filter implementation prior to render

I'm currently attempting to catch an unexpected error occurring within an asynchronous promise, specifically when updating the filter of a Power BI embedded report. However, I'm encountering difficulty in capturing this error within the catch block.

Here's a snippet of my code:

 

return new Promise((resolve, reject) => {
  let rep_res = report.updateFilters(models.FiltersOperations.Add, [filter, filter2])
    .then(() => {
      resolve('Filter Applied');
    })
    .catch((error) => {
      reject("Failed to apply filters: " + error);
    });
});

The error occurs after logging "Filter Applied" in the console and is as follows:

    Error : Error: \<rect\> attribute x: Expected length, "NaN".


I've confirmed that this error originates from the updateFilters function because removing the code associated with it eliminates the error.


The filter objects appear to be correct, as the error only occurs with a specific report.


I've consulted the Power BI documentation regarding the addition of filters to reports, but I couldn't find any guidance on error handling.


powerbi documentation to add reports: https://learn.microsoft.com/en-us/javascript/api/overview/powerbi/control-report-filters#add-new-fil...


In an attempt to resolve this issue, I've tried several approaches, including:

  • Storing the response of the then method and the promise itself in variables to find any trace of error
  • Implementing try-catch blocks
  • Using setTimeout to address asynchronous behavior
  • Utilizing window.onerror
  • Adding a setTimeout function before resolving the promise

Any assistance or insights into resolving this issue would be greatly appreciated. Thank you.

1 REPLY 1
v-yangliu-msft
Community Support
Community Support

Hi  @nckpedersen ,

 

Depending on the error message displayed, you can check the data used, possibly due to data inconsistencies or data type mismatches, to ensure that it is formatted correctly, that the data to be filtered does not contain non-numeric values and contains only numeric values

Data types in Power BI Desktop - Power BI | Microsoft Learn

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.