Filter entities in a view by referenced entity I am creating a website in Drupal 8 that shows info about team members of a business.

I've created two new content types:
- Department
- Team Member

I've created an entity reference field in team member that refers to the department he/she works for. The relation is many to many so I allowed multiple values.

Now I want to create a menu item for each department and when clicked a page shows with the team members working for that department.

I am totally new to Drupal so please explain steps in details :)

I've tried creating a view and add "Entity Reference" but I don't know how to proceed after that.
I also tried to add a filter criteria but didn't work as well.
Phase1:
You would need to construct a view using contextual filters, relationships and dynamic path (url) to display team members for a department.  


First create a view with Content type of Department. Also enable Create a page and add path like for example, /department/%. Here % is used to make your path dynamic (to pass arguments such as nid using contextual filters). Then click continue &amp; edit.    
Now in your view under the advanced section, add a reverse relationship to your team member content type. You should select something like A bridge to the content entity that is referencing content via field_teammember. The field_teammember is an entity reference field from team member content type.
Next under fields, add all the required fields you need. If you add any of your team member content type fields, do not  forget to add relationship in those fields settings.
Again under the advanced section, add contextual filters. Select Content:Nid and in the settings do not add relationship because this Nid will be of the department content type (base table of your view). 
In the same contextual filter configuration, under When the filter value is NOT available section, select provide default value and then select type as Raw value from URL. The path component value will be the position of % in your url. In the path you specified /department/%, its in the second position. Select 2 for your path component value and click apply.  


This should have already generated a view as you required.
Now to preview your view, find an Nid of any department node and paste it in the Preview with contextual filters and click update preview. This will display the team members of that department.

Phase2:
Now create a view of departments list for menu items.  


Create a view and select Content type of Department. You do not require a page for this view. Click Continue &amp; edit.
Under fields, if you already have a Title field as your department name then add only an Nid field. And in the Nid field settings enable Exclude from display.
Note: If you don't have title field as your department name, then remove the title field and add a department name field.  
Now if you are using title field, disable Link this field to the original piece of content option. Then expand Rewrite results section and enable Output this field as a link. In the link path, add your dynamic url created for previous view like www.xyz.com/department/[nid].
Note: In the link, Nid is replaced with %. This could be some other value in your view, so you need to get this from Replacement Patterns in the field settings.


This will create another view for your departments list.
Now install and enable Menu views module if you don't have it. Next in the Administrator/Structure/Menus, create a menu and in the settings select departments list view to display the list as menu items.
Hope this helps.