Grouping is one of the most powerful of Microsoft Project features. It was introduced in Project 2000 and has continued through Project 2002 and Project 2003. It is remarkably similar to the way Primavera Project Planner (P3) works with "activity codes". Grouping allows you to view the tasks in your project grouped in a number of different ways while still having the option to return to the original outline structure.
To illustrate this let's take a look at a small project. There are two teams working on a project with three phases. Within each phase is a three task iteration (Design, Develop, Test). If we enter the data and organize by the two teams and in sequential order we end up with a project which looks like this:
First right click on the column header to bring up the customize fields dialog:

Then click on "Rename Field" and change the name to something memorable and useful
You can see that this example is using text fields for "Worktype", "Phase" and "Team"
Once the fields have been filled in with the appropriate values the next step is to apply the grouping. The first time through will take a couple of clicks, but after that is it amazingly simple to apply.
Go to the "Project" menu and select "Group by", the "More Groups"

Click on the "New" button and the Group Definition dialog box comes up. Here enter the name of the group and choose the field that the group is based on. I always put an underscore _ in front of the group names I create. This puts them at the top of the list and helps me distinguish them from the built-in groups.

When this is done you are all set to apply that grouping. The end result should look something like this:

You can define similar groups for Worktype or team. Grouping allows you several levels of hierarchy so you can group by team and then by phase etc...
To return to your original state simple choose "Group by", "no group".
IIF statement. If the condition [Text2]="Phase 1"is true, then the first value "Yes"is returned. If false it returns the second value "No".

Click OK to exit and then it is time to format the barstyle. This is pretty simple. Go to the "Format" menu, Select "Barstyles". Insert a row at the bottom and call it whatever you like. Then set it to draw based on "Flag1" just as shown here:

Set up other barstyles using other flag fields until you have one for every phase or for every category you are interested in. You can see that this file has three custom barstyles. One thing to be wary of. Bars are drawn in the order they are listed in. So a wide bar at the end of the list might be drawn over a bar which is defined earlier in the list. You should define the basic barstyles at the beginning and things like baselines further down the list.
Download the Microsoft Project File (Project 2002 format) that was used for this example