<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Filtering with Power BI Embedded in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Filtering-with-Power-BI-Embedded/m-p/1148824#M24073</link>
    <description>&lt;P&gt;TL;DR: I get the error "Could not serialize filter. Could not retrieve filter values." when calling visual.getFilters() after setting a basic filter using visual.setFilters().&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am implementing a solution that takes the idea of the &lt;A href="https://microsoft.github.io/PowerBI-JavaScript/demo/v2-demo/?showcase=QuickVisualCreator" target="_blank" rel="noopener"&gt;Quick visual creator&lt;/A&gt; sample and extending it futher to also include more visual types, extended data field application and filtering. This part of my application is called Quick Builder, so I will reference it using that name below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been successful in loading different visual types, applying data fields to the different roles, retrieving the filters and setting empty filters. However, I am now attempting to set filter values and am unable to find a working solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As an example, I have saved a report via Power BI and set a filter. I load that saved report into my Quick Builder and get the filters via visual.getFilters() (where visual is a reference to a specific visual instance). When I receive the filter I saved, I see it as the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
	"$schema": "http://powerbi.com/product/schema#basic",
	"target": {
		"table": "Organization",
		"hierarchy": "Organization Region",
		"hierarchyLevel": "Region",
		"keys": ["Region.Key0"]
	},
	"filterType": 1,
	"operator": "In",
	"values": ["FSC / Operations", "Southern Region"],
	"requireSingleSelection": false,
	"keyValues": [
		[605069053],
		[-1788494854]
	]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I then have UI components that allow the user to update the filter selection. I then attempt to call visual.setFilters() with different values. I construct the filter like the below snippet.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;filter = new models.BasicFilterWithKeys(...)
/* {
	"$schema": "http://powerbi.com/product/schema#basic",
	"target": {
		"table": "Organization",
		"hierarchy": "Organization Region",
		"hierarchyLevel": "Region",
		"keys": ["Region.Key0"]
	},
	"filterType": 1,
	"operator": "In",
	"values": ["Operations", "Northern Region"],
	"requireSingleSelection": false,
	"keyValues": [
		[-1079237640],
		[174253560]
	]
} */

visual.setFilters([filter]).then(...)
.catch(...)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The visual updates to reflect the filter applied correctly. However, every time I call visual.getFilters() after that, the promise resolves in error with the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;visual.getFilters().then({...})
.catch(err =&amp;gt; {...}) // err = {"message":"Could not serialize filter. Could not retrieve filter values."}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Getting this exception when attempting to get filters completely breaks the flow of my tool because when I load the report, I am unable to get the list of filters that I need to show to allow the user to interact with.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tracked this error down in the code to &lt;A href="https://github.com/iamebadi/powerbi-hierarchySlicer-master/blob/edb14a6909ccdb3b01c2388e491e7440ad3b620b/external/jsonfilter.js#L722" target="_blank" rel="noopener"&gt;jsonfilter.js, line 722&amp;nbsp;&lt;/A&gt;where it checks for cachedValueItems when attempting to serialize a basic filter. Every time I set my own filter with values and set a breakpoint in the browser dev tools, this cachedValueItems value is undefined. When I set the filter without values (clearing the filter), the filter is successfully applied to the visual and the getFilters() function promise resolves successfully.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I specifically interact with filters on the one and only visual in the report, but the same issue exists when attempting to set page-level or report-level filters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me understand what I need to do to get this working correctly? Is there some process I need to kick off or something to set cachedValueItems for a filter?&lt;/P&gt;</description>
    <pubDate>Tue, 09 Jun 2020 12:49:08 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-06-09T12:49:08Z</dc:date>
    <item>
      <title>Filtering with Power BI Embedded</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Filtering-with-Power-BI-Embedded/m-p/1148824#M24073</link>
      <description>&lt;P&gt;TL;DR: I get the error "Could not serialize filter. Could not retrieve filter values." when calling visual.getFilters() after setting a basic filter using visual.setFilters().&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am implementing a solution that takes the idea of the &lt;A href="https://microsoft.github.io/PowerBI-JavaScript/demo/v2-demo/?showcase=QuickVisualCreator" target="_blank" rel="noopener"&gt;Quick visual creator&lt;/A&gt; sample and extending it futher to also include more visual types, extended data field application and filtering. This part of my application is called Quick Builder, so I will reference it using that name below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been successful in loading different visual types, applying data fields to the different roles, retrieving the filters and setting empty filters. However, I am now attempting to set filter values and am unable to find a working solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As an example, I have saved a report via Power BI and set a filter. I load that saved report into my Quick Builder and get the filters via visual.getFilters() (where visual is a reference to a specific visual instance). When I receive the filter I saved, I see it as the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;{
	"$schema": "http://powerbi.com/product/schema#basic",
	"target": {
		"table": "Organization",
		"hierarchy": "Organization Region",
		"hierarchyLevel": "Region",
		"keys": ["Region.Key0"]
	},
	"filterType": 1,
	"operator": "In",
	"values": ["FSC / Operations", "Southern Region"],
	"requireSingleSelection": false,
	"keyValues": [
		[605069053],
		[-1788494854]
	]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I then have UI components that allow the user to update the filter selection. I then attempt to call visual.setFilters() with different values. I construct the filter like the below snippet.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;filter = new models.BasicFilterWithKeys(...)
/* {
	"$schema": "http://powerbi.com/product/schema#basic",
	"target": {
		"table": "Organization",
		"hierarchy": "Organization Region",
		"hierarchyLevel": "Region",
		"keys": ["Region.Key0"]
	},
	"filterType": 1,
	"operator": "In",
	"values": ["Operations", "Northern Region"],
	"requireSingleSelection": false,
	"keyValues": [
		[-1079237640],
		[174253560]
	]
} */

visual.setFilters([filter]).then(...)
.catch(...)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The visual updates to reflect the filter applied correctly. However, every time I call visual.getFilters() after that, the promise resolves in error with the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;visual.getFilters().then({...})
.catch(err =&amp;gt; {...}) // err = {"message":"Could not serialize filter. Could not retrieve filter values."}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Getting this exception when attempting to get filters completely breaks the flow of my tool because when I load the report, I am unable to get the list of filters that I need to show to allow the user to interact with.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tracked this error down in the code to &lt;A href="https://github.com/iamebadi/powerbi-hierarchySlicer-master/blob/edb14a6909ccdb3b01c2388e491e7440ad3b620b/external/jsonfilter.js#L722" target="_blank" rel="noopener"&gt;jsonfilter.js, line 722&amp;nbsp;&lt;/A&gt;where it checks for cachedValueItems when attempting to serialize a basic filter. Every time I set my own filter with values and set a breakpoint in the browser dev tools, this cachedValueItems value is undefined. When I set the filter without values (clearing the filter), the filter is successfully applied to the visual and the getFilters() function promise resolves successfully.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I specifically interact with filters on the one and only visual in the report, but the same issue exists when attempting to set page-level or report-level filters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me understand what I need to do to get this working correctly? Is there some process I need to kick off or something to set cachedValueItems for a filter?&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jun 2020 12:49:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Filtering-with-Power-BI-Embedded/m-p/1148824#M24073</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-06-09T12:49:08Z</dc:date>
    </item>
  </channel>
</rss>

