0
votes

I am creating a custom filter in power bi. My basic idea is say, I have two categories "Category and Segment" , which has following values. Category -> Technology,Office Supplies, Furniture. Segment -> Consumer, Corporate, Home Office. and when user want to filter charts based on any of these values he clicks on appropriate buttons.(each value would be a button). How to achieve this?

I have been able to do create a custom filter for one category.When I put two categories filter does not work.

Here is the result with one category - with one category This works exactly with three distinct values. But when we add one more category power bi's Grouping issue comes. Meaning now the grouping is between category and segment and so nine distinct values comes. From power bi perspective its correct but what I am expecting is 6 values only , no grouping between each other. With two Category

How to overcome this?

-- Codes -- getting data.

      let viewModel: ViewModel = {
        dataPoints: []
      };
      if (
        !dv ||
        !dv[0] ||
        !dv[0].categorical ||
        !dv[0].categorical.categories ||
        !dv[0].categorical.categories[0].source
        //   || !dv[0].categorical.values
      )
        return viewModel;
      let view = dv[0].categorical;
      let categories = view.categories[0];
      console.log("Categories:-");
      console.log(categories);
      //   for (let j = 0; j < categories.length; j++) {
      for (let i = 0, len = categories.values.length; i < len; i += 1) {
        viewModel.dataPoints.push({
          category: <string>categories.values[i],
          identity: this.host
            .createSelectionIdBuilder()
            .withCategory(categories, i)
            .createSelectionId()
        });
      }
      //   }

      return viewModel;

-- saying to power bi to slice __this.selectionManager.select(element.identity); where element is each button

What I am expecting is how many ever category we put they don't group each other rather gives back distinct values of each category and for all these a button would be there. On clicking the button it filters the chart.

1
any idea how to do thisJIJO JOSEPH
Why are you trying to combine 2 different attributes in one filter? Is there anything wrong with having them on separate slicers?RADO
The idea was to have one filter for the entire dashboard where you can search based on value of any dimention and filer accordingly. I was able to do it and you can see it here github.com/dsjijo/myfiltervisualJIJO JOSEPH

1 Answers

0
votes

The approach i wsa following would not solve this issue. so i have taken another approach meaning i would always get this multiple values only since in power bi i am specifing it to be Grouping, so what i do is get the distinct using the Set opertor in js and via the filter api i am filtering.