Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Get all data from an slicer using powerbi-client js library, not only selected values

Hello comunity   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.    the first slicer ...
  • Anonymous's avatar
    Anonymous
    1 year ago

    thank you 

     

    That's right I also tried this but it didn't work

     

    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.  

    // 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);
    }