<?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 Apply Slicer on Report Load in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Apply-Slicer-on-Report-Load/m-p/682390#M19294</link>
    <description>&lt;P&gt;&lt;SPAN&gt;I have an embed Bi report.&amp;nbsp; &amp;nbsp; I need to preset a filter on the report.&amp;nbsp; &amp;nbsp; I can get this working when I run the first piece of code AFTER the report has finished loading.&amp;nbsp; &amp;nbsp;I need this to be done before so that the filter is pre applied.&amp;nbsp; I have tried following the instructions and appeding the slicers to my initial config using the second peice of code but it does not work.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;img /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;setFilter1() {
    this.biReport.getPages()
      .then(function (pages) {
        var firstPage = pages[1];
        firstPage.getVisuals()
          .then(function (visuals) {
            let visual = visuals.filter(x =&amp;gt; x.title === 'Current/Previous Month')[0];
            if (visual) {
              const basicFilter = {
                $schema: 'http://powerbi.com/product/schema#basic',
                target: {
                  table: 'WorkOrdersView',
                  column: 'Current/PreviousMonth'
                },
                operator: 'In',
                values: ['Current Month'],
                filterType: pbi.models.FilterType.Basic
              };
              visual.getSlicerState().then(slicer =&amp;gt; {
                slicer.filters = [];
                visual.setSlicerState({
                  filters: [basicFilter]
                }).then(s =&amp;gt; {
                  this.myslicers = s;
                }).catch(errors =&amp;gt; {
                  console.log(errors);
                });
              });
            }
          });
      });
  }&lt;/PRE&gt;&lt;PRE&gt; slicers = [
    {
      selector: {
        $schema: 'http://powerbi.com/product/schema#visualSelector',
        visualName: 'c21a3d6790798afcfb8c'
      },
      filters: [
        {
          $schema: 'http://powerbi.com/product/schema#basic',
          target: {
            table: 'WorkOrdersView',
            column: 'Current/PreviousMonth'
          },
          operator: 'In',
          values: ['Current Month']
        }
      ]
    }
  ];
  embedConfig = {
    type: 'report',
    id: '',
    slicers: [this.slicers],
    embedUrl: '',
    tokenType: pbi.models.TokenType.Embed,
    accessToken: ''
  };&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 02 May 2019 11:01:02 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2019-05-02T11:01:02Z</dc:date>
    <item>
      <title>Apply Slicer on Report Load</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Apply-Slicer-on-Report-Load/m-p/682390#M19294</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I have an embed Bi report.&amp;nbsp; &amp;nbsp; I need to preset a filter on the report.&amp;nbsp; &amp;nbsp; I can get this working when I run the first piece of code AFTER the report has finished loading.&amp;nbsp; &amp;nbsp;I need this to be done before so that the filter is pre applied.&amp;nbsp; I have tried following the instructions and appeding the slicers to my initial config using the second peice of code but it does not work.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;img /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;setFilter1() {
    this.biReport.getPages()
      .then(function (pages) {
        var firstPage = pages[1];
        firstPage.getVisuals()
          .then(function (visuals) {
            let visual = visuals.filter(x =&amp;gt; x.title === 'Current/Previous Month')[0];
            if (visual) {
              const basicFilter = {
                $schema: 'http://powerbi.com/product/schema#basic',
                target: {
                  table: 'WorkOrdersView',
                  column: 'Current/PreviousMonth'
                },
                operator: 'In',
                values: ['Current Month'],
                filterType: pbi.models.FilterType.Basic
              };
              visual.getSlicerState().then(slicer =&amp;gt; {
                slicer.filters = [];
                visual.setSlicerState({
                  filters: [basicFilter]
                }).then(s =&amp;gt; {
                  this.myslicers = s;
                }).catch(errors =&amp;gt; {
                  console.log(errors);
                });
              });
            }
          });
      });
  }&lt;/PRE&gt;&lt;PRE&gt; slicers = [
    {
      selector: {
        $schema: 'http://powerbi.com/product/schema#visualSelector',
        visualName: 'c21a3d6790798afcfb8c'
      },
      filters: [
        {
          $schema: 'http://powerbi.com/product/schema#basic',
          target: {
            table: 'WorkOrdersView',
            column: 'Current/PreviousMonth'
          },
          operator: 'In',
          values: ['Current Month']
        }
      ]
    }
  ];
  embedConfig = {
    type: 'report',
    id: '',
    slicers: [this.slicers],
    embedUrl: '',
    tokenType: pbi.models.TokenType.Embed,
    accessToken: ''
  };&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 11:01:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Apply-Slicer-on-Report-Load/m-p/682390#M19294</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-05-02T11:01:02Z</dc:date>
    </item>
  </channel>
</rss>

