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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Neehar
Helper I
Helper I

How to retrieve Slicers Data prom power BI report

Hello,

 

I want to retrieve the Slicers data in a power bi report from all the pages.

 

I tried the below code, which is provided in the url getSlicers()

 

page.getSlicers()
        .then(slicers => {
            debugger
            console.log(slicers);
        });

 I thrown an error Uncaught (in promise) TypeError: page.getSlicers is not a function.

 

Please help me with a working example.

 

Thank You

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

HI @Neehar,

I'd like to suggest you test on the power bi playground, it shared the sample report and corresponding code snaps of each operation:

Power BI Playground - Developer Sandbox

// Retrieve the page collection and get the slicers for the active page.
try {
    const pages = await report.getPages();

    // Retrieve the active page.
    let pageWithSlicer = pages.filter(function (page) {
        return page.isActive;
    })[0];

    const visuals = await pageWithSlicer.getVisuals();

    // Retrieve all visuals with the type "slicer".
    let slicers = visuals.filter(function (visual) {
        return visual.type === "slicer";
    });

    slicers.forEach(async (slicer) => {
        // Get the slicer state.
        const state = await slicer.getSlicerState();
        console.log("Slicer name: \"" + slicer.name + "\"\nSlicer state:\n", state);
    });
}
catch (errors) {
    console.log(errors);
}

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

HI @Neehar,

I'd like to suggest you test on the power bi playground, it shared the sample report and corresponding code snaps of each operation:

Power BI Playground - Developer Sandbox

// Retrieve the page collection and get the slicers for the active page.
try {
    const pages = await report.getPages();

    // Retrieve the active page.
    let pageWithSlicer = pages.filter(function (page) {
        return page.isActive;
    })[0];

    const visuals = await pageWithSlicer.getVisuals();

    // Retrieve all visuals with the type "slicer".
    let slicers = visuals.filter(function (visual) {
        return visual.type === "slicer";
    });

    slicers.forEach(async (slicer) => {
        // Get the slicer state.
        const state = await slicer.getSlicerState();
        console.log("Slicer name: \"" + slicer.name + "\"\nSlicer state:\n", state);
    });
}
catch (errors) {
    console.log(errors);
}

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.