<?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 Re: Get all data from an slicer using powerbi-client js library, not only selected values in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Get-all-data-from-an-slicer-using-powerbi-client-js-library-not/m-p/4031091#M54034</link>
    <description>&lt;P&gt;Hello&amp;nbsp;@Anonymous&lt;/a&gt;&amp;nbsp; I tested what you recomended, but unfortunatelly the function&amp;nbsp;&lt;STRONG&gt;getFilters()&amp;nbsp;&lt;/STRONG&gt;doesn't contain a definition for property&amp;nbsp;&lt;STRONG&gt;values,&amp;nbsp;&lt;/STRONG&gt;so I wasn't able to access the values loaded in the dropd down slicer filter as you can see in the next screenshot.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="osb1_0-1720472760260.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1128624i896B177E322F79E7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="osb1_0-1720472760260.png" alt="osb1_0-1720472760260.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 10 Jul 2024 23:00:17 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2024-07-10T23:00:17Z</dc:date>
    <item>
      <title>Get all data from an slicer using powerbi-client js library, not only selected values</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Get-all-data-from-an-slicer-using-powerbi-client-js-library-not/m-p/4021322#M53857</link>
      <description>&lt;P&gt;Hello comunity&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working in one implementation using the library powerbi-client javascript library to embedd a pbix report in my web, this report has 2 slicer with data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the first slicer has a list of years&amp;nbsp;&lt;/P&gt;&lt;P&gt;the second slicer has a list of texts&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if you select a value in the first slicer, values in the second slicer will change because it depends on the first.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Analyzing the powerbi sandbox page I found the way to set values from my web to my embedded report using javascript, and it is working fine, but now I realized that if I send a value that doesn't exist in the slicer, the value appears in the list.&lt;BR /&gt;&lt;BR /&gt;i.e. my first slicer has as values&lt;/P&gt;&lt;P&gt;2021&lt;/P&gt;&lt;P&gt;2022&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I send the value 2023 (this doesn't exist in the slicer)&lt;BR /&gt;&lt;BR /&gt;using the next code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;``` part of the implementation is not added in this code example

let pageWithSlicer = pages.filter(function (page) {
 return page.isActive;
})[0];

const visuals = await pageWithSlicer.getVisuals();
            
// Retrieve the target visual.
let slicer = visuals.filter(function (visual) {
 return visual.type === "slicer" &amp;amp;&amp;amp; visual.title.includes(sliceName);
})[0];

await slicer.setSlicerState({ filters: [filter] });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;the slicer now has the next values&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;2021&lt;BR /&gt;2022&lt;BR /&gt;2023&lt;BR /&gt;&lt;BR /&gt;I was wondering if anybody could help me know if there's any way to avoid having new values in slicer when this value doesn't exist as a valid value, or could you please help me know if there's any way to get the data from an slicer so that I will be able to check agains the value sent via web.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind Regards!&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2024 21:54:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Get-all-data-from-an-slicer-using-powerbi-client-js-library-not/m-p/4021322#M53857</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-07-02T21:54:10Z</dc:date>
    </item>
    <item>
      <title>Re: Get all data from an slicer using powerbi-client js library, not only selected values</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Get-all-data-from-an-slicer-using-powerbi-client-js-library-not/m-p/4022510#M53873</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you may need to update your code to check whether the value is valid.&lt;/P&gt;
&lt;P&gt;You may refer to the code as below and I hope it could help you to resolve your issue.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;const slicer = visuals.find((visual) =&amp;gt; visual.type === 'slicer' &amp;amp;&amp;amp; visual.title.includes(sliceName));



if (slicer) {

    // Get all slicer data (valid options)

    const slicerData = await slicer.getFilters();



    // Check if the value you want to set exists in the slicer data

    const valueToSet = '2023'; // Example value

    const isValidValue = slicerData.some((item) =&amp;gt; item.values.includes(valueToSet));



    if (isValidValue) {

        // Set the slicer state

        await slicer.setSlicerState({ filters: [filter] });

    } else {

        console.log(`Invalid value: ${valueToSet}`);

    }

} else {

    console.log('Slicer not found.');

}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the related document, you can view this content:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/javascript/api/powerbi/powerbi-client/" target="_blank"&gt;powerbi-client package | Microsoft Learn&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/javascript/api/overview/powerbi/control-report-slicers" target="_blank"&gt;Use slicers in Power BI embedded analytics | Microsoft Learn&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Liu Yang&lt;/P&gt;
&lt;P&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;EM&gt;Accept it as the solution&lt;/EM&gt; to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2024 09:13:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Get-all-data-from-an-slicer-using-powerbi-client-js-library-not/m-p/4022510#M53873</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-07-03T09:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: Get all data from an slicer using powerbi-client js library, not only selected values</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Get-all-data-from-an-slicer-using-powerbi-client-js-library-not/m-p/4031091#M54034</link>
      <description>&lt;P&gt;Hello&amp;nbsp;@Anonymous&lt;/a&gt;&amp;nbsp; I tested what you recomended, but unfortunatelly the function&amp;nbsp;&lt;STRONG&gt;getFilters()&amp;nbsp;&lt;/STRONG&gt;doesn't contain a definition for property&amp;nbsp;&lt;STRONG&gt;values,&amp;nbsp;&lt;/STRONG&gt;so I wasn't able to access the values loaded in the dropd down slicer filter as you can see in the next screenshot.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="osb1_0-1720472760260.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1128624i896B177E322F79E7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="osb1_0-1720472760260.png" alt="osb1_0-1720472760260.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2024 23:00:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Get-all-data-from-an-slicer-using-powerbi-client-js-library-not/m-p/4031091#M54034</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-07-10T23:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: Get all data from an slicer using powerbi-client js library, not only selected values</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Get-all-data-from-an-slicer-using-powerbi-client-js-library-not/m-p/4239246#M57799</link>
      <description>&lt;P&gt;That's right I also tried this but it didn't work&lt;/P&gt;&lt;P&gt;I think powerbi library is not too much clear about what we can do as a developers. After several testing I found a function that can help to grab data from the slicer, it can be used to try to pre-validate what you want to send against slicer data and avoid having non existing values.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;// Retrieve the page collection and get the visuals for the active page.
try {
    const pages = await report.getPages();

    // Retrieve the page that contain the visual. For the sample report it will be the active page
    let page = pages.filter(function (page) {
        return page.isActive
    })[0];

    const visuals = await page.getVisuals();

    // Retrieve the target visual.
    let visual = visuals.filter(function (visual) {
        return visual.name === "VisualContainer4";
    })[0];

    const result = await visual.exportData(models.ExportDataType.Summarized);
    console.log(result.data);
}
catch (errors) {
    console.log(errors);
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2024 19:25:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Get-all-data-from-an-slicer-using-powerbi-client-js-library-not/m-p/4239246#M57799</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-10-11T19:25:17Z</dc:date>
    </item>
    <item>
      <title>Re: Get all data from an slicer using powerbi-client js library, not only selected values</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Get-all-data-from-an-slicer-using-powerbi-client-js-library-not/m-p/4239247#M57800</link>
      <description>&lt;P&gt;thank you&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That's right I also tried this but it didn't work&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think powerbi library is not too much clear about what we can do as a developers. After several testing I found a function that can help to grab data from the slicer, it can be used to try to pre-validate what you want to send against slicer data and avoid having non existing values.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;// Retrieve the page collection and get the visuals for the active page.
try {
    const pages = await report.getPages();

    // Retrieve the page that contain the visual. For the sample report it will be the active page
    let page = pages.filter(function (page) {
        return page.isActive
    })[0];

    const visuals = await page.getVisuals();

    // Retrieve the target visual.
    let visual = visuals.filter(function (visual) {
        return visual.name === "VisualContainer4";
    })[0];

    const result = await visual.exportData(models.ExportDataType.Summarized);
    console.log(result.data);
}
catch (errors) {
    console.log(errors);
}&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2024 19:25:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Get-all-data-from-an-slicer-using-powerbi-client-js-library-not/m-p/4239247#M57800</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-10-11T19:25:55Z</dc:date>
    </item>
  </channel>
</rss>

