Hi, you can use string pattern matching or sub string method to form groups and apply filter on them. I used "find function" to find the sub string to find the department and subject of student.
Below is a snap of calculative field to group students by Department.
Below is a snap of calculative field to group students by Subject codes.
Drag an drop both groups in the filter shelf to apply filters.
Sample visualization after applying filters.
Hope this helps you.