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 a group by using SharePoint Designer:

  • Create a List view from SharePoint web user interface
  • Edit the view page in Advanced mode using SharePoint Designer.  Search for “<Query/>” and replace it with:
       <GroupBy Collapse='FALSE' GroupLimit='30' >
             <FieldRef Name='ContentType' />
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 SharePoint Online list and use this PowerShell CSOM script to update the list view’s group by using “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
$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)

    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

        Write-host "View Updated Successfully!" -f Green
        Write-host "View '$ViewName' Doesn't exist in the List!"  -f Yellow
Catch {
    write-host -f Red "Error Updating List View!" $_.Exception.Message
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 is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply