Forum Discussion

marcobaciga's avatar
marcobaciga
Helper I
8 years ago
Solved

set value field in report powerbi by custom visual

Hi,

I must in m y custom visual to send a value like filter in each visual object in my report powerbi when i click a icon.

Is it possible?

 

Thank you

 

Marco

 

  • v-viig's avatar
    v-viig
    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

    [email protected]

15 Replies

    • marcobaciga's avatar
      marcobaciga
      Helper I

      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-viig's avatar
        v-viig
        Community 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

        [email protected]