Forum Discussion
set value field in report powerbi by custom visual
- 8 years ago
This code snippet is going to address the issue:
let selectionIds = []; selectionIds.push(host.createSelectionIdBuilder() .withCategory(categorical.categories[0], 0) .createSelectionId() ); selectionIds.push(host.createSelectionIdBuilder() .withCategory(categorical.categories[1], 0) .createSelectionId() ); selectionIds.push(host.createSelectionIdBuilder() .withCategory(categorical.categories[0], 1) .createSelectionId() ); selectionIds.push(host.createSelectionIdBuilder() .withCategory(categorical.categories[1], 1) .createSelectionId() ); selectionIds.forEach((selectionId) => { this.selectionManager.select(selectionId, true) });Ignat Vilesov,
Software Engineer
Microsoft Power BI Custom Visuals
There're three ways to filter/select values:
Please let me know if you have any questions.
Ignat Vilesov,
Software Engineer
Microsoft Power BI Custom Visuals
Thank you v-viig,
I have see this link Handling Visual Selection but i dont understand.
I have two categories in my custom visual and when i click i have to filter this two values.
Do you have a code for example?
Thanks
Marco Baciga,
BI Consultant@24Consulting
- v-viig8 years agoCommunity Champion
Could you please sahre your capabilities.json?
As far as I understand the requirement, you sould use this code snippet to create a SelectionId for each category:
let dataViews = options.dataViews // options: VisualUpdateOptions let categorical = dataViews[0].categorical; let categoryIndex: number = 0; // Index of category let i: number = 0; // this is index of your value in the category let selectionId = host.createSelectionIdBuilder() .withCategory(categorical.categories[categoryIndex], i) .createSelectionId();After that, you should use selectionManager.select method to select categories:
this.selectionManager.select(selectionId, true).then((ids: ISelectionId[]) => { //called when setting the selection has been completed successfully });Please let me know if you have any questions.
Ignat Vilesov,
Software Engineer
Microsoft Power BI Custom Visuals
- marcobaciga8 years agoHelper I
Thank you v-viig,
i try your code and it runs.
I have tried to pass the array selectionId in selectionManager.select but it doesnt run.
I write my code
let selectionId = [];
selectionId [0] = host.createSelectionIdBuilder()
.withCategory(categorical.categories[0], 0).withCategory(categorical.categories[1], 0)
.createSelectionId();selectionId [1] = host.createSelectionIdBuilder()
.withCategory(categorical.categories[0],1).withCategory(categorical.categories[1], 1)
.createSelectionId();this.selectionManager.select(selectionId, true).then((ids: ISelectionId[]) => {
//called when setting the selection has been completed successfully
});Where is wrong?
Thank you
Marco Baciga@24COnsulting
BI COnsultant
- v-viig8 years agoCommunity Champion
This code snippet is going to address the issue:
let selectionIds = []; selectionIds.push(host.createSelectionIdBuilder() .withCategory(categorical.categories[0], 0) .createSelectionId() ); selectionIds.push(host.createSelectionIdBuilder() .withCategory(categorical.categories[1], 0) .createSelectionId() ); selectionIds.push(host.createSelectionIdBuilder() .withCategory(categorical.categories[0], 1) .createSelectionId() ); selectionIds.push(host.createSelectionIdBuilder() .withCategory(categorical.categories[1], 1) .createSelectionId() ); selectionIds.forEach((selectionId) => { this.selectionManager.select(selectionId, true) });Ignat Vilesov,
Software Engineer
Microsoft Power BI Custom Visuals