You might have come across situations where you need to analyze and summarize data by week in Google Sheets. While Excel Pivot Tables have a feature to group data by days and select a number of days to get a weekly summary, unfortunately, this feature is not available in Google Sheets. But don’t worry, I’m here to show you two simple approaches to group data by week in a Pivot Table in Google Sheets.
Approach 1: Grouping by Week Numbers
To group data by week numbers in a Pivot Table, follow these steps:
- Start by preparing your data. In this example, let’s assume you have dates in column A and expenses in column B.
- Add a helper column, C, and enter the field label ‘Week’ in cell C1.
- In cell C2, enter the formula
=ArrayFormula(IFERROR(WEEKNUM(DATEVALUE(A2:A), 1)))
. This formula converts the dates into week numbers. - Now, you can create a Pivot Table by clicking on Insert > Pivot Table.
- In the Pivot Table editor, under “Data Range,” enter
A:C
to include all the data. - Select where you want the Pivot Table to be inserted, either in the current sheet or a new sheet.
- Click “Create” to generate the layout.
- Add the ‘Week’ field to the Rows and the ‘Expenses’ field to the Values.
- Voila! You have successfully grouped the data by week numbers in the Pivot Table.
Approach 2: Grouping by Week Ranges
If you prefer to group the data by week ranges, here’s what you need to do:
-
Start by preparing your data. Follow the same steps as in Approach 1 to create the ‘Week’ helper column.
-
In cell C2, enter the following formula:
=ArrayFormula(LET(range, A2:A, n, (MAX(range)-MIN(range))/7, weeks, IFNA(HSTACK(SEQUENCE(n+1, 1, MIN(range), 7), IFERROR(SEQUENCE(n, 1, MIN(range)+6, 7), MAX(range))), MAX(range)), formatted, HSTACK(TEXT(SEQUENCE(ROWS(weeks)), "00."), TEXT(CHOOSECOLS(weeks, 1), "DD/MM/YYYY"), IF(CHOOSECOLS(weeks, 1), "-",), TEXT(CHOOSECOLS(weeks, 2), "DD/MM/YYYY")), weekrange, TRANSPOSE(QUERY(TRANSPOSE(formatted),, 9^9)), XLOOKUP(range, CHOOSECOLS(weeks, 1), weekrange, ,-1)))
This formula converts the dates into week ranges.
-
Follow the same steps as in Approach 1 to create a Pivot Table, but this time, add the ‘Week’ field to the Rows and the ‘Expenses’ field to the Values.
-
Congratulations! You have successfully grouped the data by week ranges in the Pivot Table.
Bonus Tip: Aligning Group by Week Number and Week Range Results
After grouping the data using both approaches, you might notice that the results may not match. Don’t worry; you can align them by following these steps:
- In any blank cell, enter the formula
=MIN(A2:A)-WEEKDAY(MIN(A2:A))+1
to find the Sunday prior to the lowest date in column A. - Manually enter the date returned by the formula under the first non-blank cell in column A.
- In the Pivot Table editor, add the ‘Date’ field above the ‘Week’ field.
- Right-click on any date in the Pivot Table report and select “Create pivot date group,” then “Year.”
- Now, your results from both approaches will be aligned.
That’s it! You now know how to group data by week in a Pivot Table in Google Sheets using two different approaches. Have fun analyzing and summarizing your data!
For more helpful tips and tricks on Google Sheets, visit Crawlan.com.
Resources: