The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Hello,
I have a report with a categorical slicer. This slicer has "single select" checked and renders as a "one selection" visual:
However, when I use the client API in embed mode, when I get this slicer and then run `const state = await slicer.getState()`
the `state.filters[0].requireSingleSelection` is always set to false whatever the check status on my report.
Is it a known issue or is it because I get the wrong attribute?
Hi @FrançoisD ,
Please review the following links, hope they can help get the expected result...
Slicers · microsoft/PowerBI-JavaScript Wiki · GitHub
let state = await visual.getSlicerState();
// Get the list of visuals from the report
report.getPages()
.then(function(pages) {
return pages[0].getVisuals();
})
.then(function(visuals) {
// Find the slicer visual by name or other properties
let slicer = visuals.find(function(visual) {
return visual.type === 'slicer' && visual.name === 'SlicerVisualName';
});
// Get the state of the slicer
return slicer.getSlicerState();
})
.then(function(slicerState) {
// Access the selected value
let selectedValue = slicerState.targets[0].target;
console.log('Selected Value:', selectedValue);
})
.catch(function(errors) {
console.error(errors);
});
Best Regards
Hello,
Thanks for your reply but, it does not answer my question at all.
I am already using the getSlicerState function and I can already get the selected value and even set it.
My issue is that I cannot programmatically make the difference between a slicer that only accept one selected value and a slicer that accept many because the "requireSingleSelection" boolean is always set to "false" in the state.filters attribute.
Regards