Group By Content Type in SharePoint Online List View

Requirement: Set a List View Group by Content Type in SharePoint Online.

How to Set a SharePoint Online View Group by Content Type?

If you want to set a list view’s group by option based on “Content Type”, there is no option from the web interface (because “Content Type” is missing from the list of columns in the drop-down!). Here is how you can group by content type.

Option #1: Edit the ListView using SharePoint Designer

Here is how you can set group by using SharePoint Designer:

  1. Create a List View from the SharePoint web user interface
  2. Edit the view page in Advanced mode using SharePoint Designer.  Search for “<Query/>” and replace it with:
<Query>
       <GroupBy Collapse='FALSE' GroupLimit='30' >
             <FieldRef Name='ContentType' />
       </GroupBy>
</Query>
sharepoint online view group by content type

This method works on SharePoint On-premises as well.

Option #2: Use PowerShell to Group by “Content Type” in SharePoint Online

Create a list view in the SharePoint Online list and use this PowerShell CSOM script to update the list view’s group by using the “ContentType” field.

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
 
#Set parameter values
$SiteURL="https://Crescent.sharepoint.com/"
$ListName ="Documents"
$ViewName="All Documents"
 
Try {
    #Setup Credentials to connect
    $Cred= Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
  
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials
    
    #Get the List
    $List = $Ctx.Web.Lists.GetByTitle($ListName)

    #Get the view to update
    $View = $List.Views.GetByTitle($ViewName)
    $Ctx.ExecuteQuery()

    if($View -ne $NULL)  
    {
        #Define the CAML Query to Group by Content Type 
        $Query= "<GroupBy Collapse='FALSE' GroupLimit='30' ><FieldRef Name='ContentType' /></GroupBy>"

        #Update the View
        $View.ViewQuery = $Query
        $View.Update()
        $Ctx.ExecuteQuery()

        Write-host "View Updated Successfully!" -f Green
    }
    else
    {
        Write-host "View '$ViewName' Doesn't exist in the List!"  -f Yellow
    }
}
Catch {
    write-host -f Red "Error Updating List View!" $_.Exception.Message
}

This will group the items in your list view based on their content type.

There is an another trick on modern lists: Append “?groupBy=ContentType” to the View URL and hit Enter in the browser, then use “Save View as” to create a new view with group by content type!

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

One thought on “Group By Content Type in SharePoint Online List View

  • It is now possible to do this via the ui when viewing the list itself, still not possible in the actual view editor…

    I have a slightly different problem though, trying to group by two fields with the second being ContentType. It just shows me the GUID, wondering if you get the same thing? Using “Add-PnPView”

    $query = ‘

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *