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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
BeenSearching
Frequent Visitor

Multi value category + Adhoc Filter

I have a list of employees with category fields that define each employee's work type. Employees can have more than one type. Here is an example: 

1.PNG

 

So far I've been able to find varias ways to make the employee count from each category appear correctly in a bar graph like this:

 

2.PNG

 

However, the solutions I've found don't allow me to use the bar chart as a way to ad-hoc filter other visuals. I click on Category1 for example and nothing happens in the other visuals.

 

How can I build a bar chart that allows me to ad-hoc filter other visuals on the page?

 

Thanks for any help the community can offer. 

 

 

Also, this Solution was very close but relies on a filter visualization. I'm hoping to find a way to make it work using the bar chart. 

1 ACCEPTED SOLUTION
v-caliao-msft
Employee
Employee

@BeenSearching,

 

You could unpivot this table, and then count the Cateogrys.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMgABQyUdJefEktT0/KJKZLYRkK0UqwNVBeahSsLYxghVxhBV2CVNiLLIlCiLzIhSZQ53DkLMAs0V2HVa4nErpnJDA9KU4w/yWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Employee = _t, Category1 = _t, Category2 = _t, Category3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee", Int64.Type}, {"Category1", type text}, {"Category2", type text}, {"Category3", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Employee"}, "Attribute", "Value"),
    #"Removed Blank Rows" = Table.SelectRows(#"Unpivoted Columns", each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null})))
in
    #"Removed Blank Rows"

Capture.PNG

 

 

Capture1.PNG

 

Regards,

Charlie Liao

View solution in original post

2 REPLIES 2
v-caliao-msft
Employee
Employee

@BeenSearching,

 

You could unpivot this table, and then count the Cateogrys.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMgABQyUdJefEktT0/KJKZLYRkK0UqwNVBeahSsLYxghVxhBV2CVNiLLIlCiLzIhSZQ53DkLMAs0V2HVa4nErpnJDA9KU4w/yWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Employee = _t, Category1 = _t, Category2 = _t, Category3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee", Int64.Type}, {"Category1", type text}, {"Category2", type text}, {"Category3", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Employee"}, "Attribute", "Value"),
    #"Removed Blank Rows" = Table.SelectRows(#"Unpivoted Columns", each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null})))
in
    #"Removed Blank Rows"

Capture.PNG

 

 

Capture1.PNG

 

Regards,

Charlie Liao

TomMartens
Super User
Super User

Hey,

 

you have to build a many to many relationship, this means you need three tables:

 

  • employee
  • category
  • employees_categories

build the following relationships:

  • category (one) and employees_categories (many) cross filter direction "Single"
  • employee (one) and employees_categories (many) cross filter direction "Both"

Hide the table employees_categoriees from report view

 

Create a measure that counts distinct the employees in the table employees_categories like so

employees count = 
calculate(
  distinctcount('employees_categories'[employee])
)

Hope this helps, if not please create sample data that we can easily recreate, e.g. upload a pbix to OneDrive or Dropbox and share the link



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.