How to do a Multi-Level Grouping in a SharePoint 2013 View Using SharePoint Designer

This article shows how to do a multi-level grouping in a SharePoint 2013 view using only SharePoint Designer 2013. I have created a list by importing data from Excel data sheets. The sample was provided by Microsoft for Power Pivot examples.
 
The default view looks as shown below. Let's say we want to group by BikeBuyer, then by Gender and then by Occupation.
 
 
To begin, click on Edit List so that it opens in SharePoint Designer. Click on New View, provide it a name and delete the default XSLT List View Web Part. Now Insert a Empty Data View Web Part. You will see as greyed icon as shown below.
 
 
In the Code View Tools, Edit and click on Parse HTML.
 
 
Now you can insert the empty web part, thne you will see a partial XSLT as shown below.
 
 
Click on Customize XSLT, you will see a complete xslt mark-up as shown below. Though I have shown this in List View Tools, the same is available in Data View Tools.
 
 
Click on Insert then select Data Source then your list.
 
 
Choose the fields from the data source and save Insert Selected Field As Multiple View Item. Save the work and see it the basic view. It is seen correctly.
 
 
Click on Sort & Group in Data View Tools, the Options tab. Add the first-level grouping.
 
 
Then add a second and third level of grouping. Add the required field and click on Edit Sort Expression, then use the concat formula to add the first-level grouping before the current field. For example, concat ('BikeBuyer: ',@BikeBuyer, ' | Gender:',@Gender).
 
Use Intellisense to choose field names so that they are not misspelled.
 
 
You need to do this for each level of grouping. For the third level, concatenate the first two. For the fourth level, the first three and so on.  Choose Show Group Header and Group Footer checkboxes. Once done, save the work and check the view. You would see something as in the following. 
 
 
There are many options, like pagination, color and other that can be tweaked. And since the entire XSLT is viewed, a few variables can be added for the totalling of fields and displaying as required. I hope this helps.