How to format a group header to display the week day in Microsoft Lists

While working with Microsoft lists the other day came up with a solution to create a custom list view to display the items created during the current week, before jumping into this article I recommend you have a look to the original post here, to get familiar with this concept.

In this post I’ll show how to format the view group headers using a custom list formatting that shows the day of the week and the number of items created.

How to format a group header to display the week day in Microsoft Lists

This list view formatting will translate the weekday represented by a number into the actual weekday in English so you can easily understand when each item was created, to implement it you should do the following:

  1. Create the calculated date columns that identify the creation week and week day of the items as explained here
  2. Group the items by weekday, if you are not familiar with this concept have a look here
  3. Once items are grouped you will see the name of the column followed by a number that represents the weekday and the number of icons for that specific day
  4. Click in the view selection option to open the context menu
  5. From the menu click on Format current view
    How to format a group header to display the week day in Microsoft Lists
  6. In the side panel click on Advanced mode located at bottom of the window
  7. Replace the existing JSON by the one below
    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
      "groupProps": {
        "headerFormatter": {
          "elmType": "div",
          "style": {
            "flex-direction": "row"
          },
          "children": [
            {
              "elmType": "div",
              "style": {
                "padding": "4px 8px 5px 8px",
                "border-radius": "6px",
                "font-weight": "500"
              },
              "attributes": {
                "class": {
                  "operator": "+",
                  "operands": [
                    "ms-bgColor-themePrimary ",
                    "ms-fontColor-white"
                  ]
                }
              },
              "children": [
                {
                  "elmType": "span",
                  "style": {
                    "padding-right": "6px",
                    "padding-top": "2px"
                  }
                },
                {
                  "elmType": "div",
                  "style": {
                    "display": "inline-flex",
                    "padding-right": "9px"
                  },
                  "children": [
                    {
                      "elmType": "div",
                      "style": {
                        "padding-left": "5px"
                      },
                      "attributes": {
                        "class": "ms-fontWeight-bold"
                      },
                      "txtContent": "=if(@group.fieldData.displayValue == '0', 'Monday', if(@group.fieldData.displayValue == '1', 'Tuesday', if(@group.fieldData.displayValue == '2', 'Wednesday', if(@group.fieldData.displayValue == '3', 'Thursday', if(@group.fieldData.displayValue == '4', 'Friday', if(@group.fieldData.displayValue == '5', 'Saturday', if(@group.fieldData.displayValue == '6', 'Sunday','')))))))"
                    },
                    {
                      "elmType": "div",
                      "style": {
                        "padding-left": "5px"
                      },
                      "attributes": {
                        "class": "ms-fontWeight-normal"
                      },
                      "txtContent": {
                        "operator": "+",
                        "operands": [
                          " - ",
                          "=@group.count",
                          "= if(@group.count!= 1,' items',' item')"
                        ]
                      }
                    }
                  ]
                }
              ]
            }
          ]
        }
      }
    }
    
  8. Click Save

The result should be similar to what is displayed in the following picture with each weekday formatted with the main color of Microsoft Lists or the main color applied to a SharePoint site followed by the number of items for the day.

How to format a group header to display the week day in Microsoft Lists

This formatting was inspired by a solution published by Michele Mended in the PnP GitHub repository available here.


No comments yet

Leave a Reply


I've been working with Microsoft Technologies over the last ten years, mainly focused on creating collaboration and productivity solutions that drive the adoption of Microsoft Modern Workplace.