- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to group by week in pivot table?
A pivot table is an essential tool present in MS Excel that rapidly analyzes and summarizes large voluminous of data in a table format. Grouping data by week usually means that the provided data is categorized by using week. This article covers three examples, first two examples are using the same strategy with a day or period difference of a week. But, in the last example, use a helper column to perform the same task, this helper column can be manipulated with the help of provided column.
Example 1: To group the week in the pivot table by using 7 day or single period week
To understand the process of grouping provided a date by a week, using the 7-day concept. Consider below given pivot table −
Go to the table and right-click on any date available in the table. This will open a menu bar with multiple options. Select the option “Group…”. Consider the below-given image for reference −
This will open the “Grouping” dialog box. This dialog box contains many fields. Under the “Auto” category user can set the starting date under the “Starting at” input label, and secondly under the end date user can set the end data under the “Ending at” option. Under the “by” option list user can set the option according to the requirement.
Users can manually enter data into both the provided field if required. But, for this example, the data range is already selected, and the displayed date is accurate. So, there is no need to modify the provided date. However, if the user wants, then changing data is possible. Move to the next header “by”. Since, in the example, the user wants to create 7 days. Thus, select the “Days” option. Now, go down and the “Number of days” option is found, then select “7”. Click on “OK”. Consider the below-depicted image for proper reference −
This will display the given data as a 1-week range. Consider the results provided in the below snapshot −
Example 2: To group the week in pivot table by using the 4-period week concept
Group four weeks in a pivot table. Consider the below-given spreadsheet, and right-click on the date column.
Select the “Group” option. As shown below −
This will open the “Grouping” dialog box, and then select the Starting at, and Ending at date accordingly. In the by section select “Days”. Set the Number of days as “28”, and press “OK”.
The above step will provide a consolidated data of 4 weeks.
Example 3: To group the week in the pivot table by using the helper column
Consider the below given below spreadsheet. The below given worksheet contains the date, sales, and week column.
Go to the E3 cell, and type the formula
“=YEAR(C3)&" "&TEXT(WEEKNUM(C3,2),"00")” and press “Enter” key.
YEAR(C3) returns the year value of the date in cell C3.
"&" is used for concatenation.
"-" is a string literal that will be included in the concatenated text.
TEXT(WEEKNUM(C3,2),"00") returns the week number of the date in cell C3, with the second argument specifying that the week starts on Monday. The "00" format code ensures that the week number is displayed with two digits.
Put all these together with the "&" concatenation operator. Getting a text string that represents the year and week number of the date in cell C3 in the format of "YYYY-WW", where YYYY is the four-digit year value and WW is the two-digit week number.
The results are displayed below −
Click on the plus “+” sign at the bottom of the cell and then drag the cell to the 10 rows, to copy the same formula for all the available cells.
After that go to the “Insert” tab, and then select the option “Tables” option, select the option “Pivot Table”, then select “From Table/Range”.
This will open the “PivotTable from table or range” dialog box. In the open dialog select the available table range. And in the “choose where you want the PivotTable to be placed” label, select the option “New worksheet”. Finally, click on the “OK” button.
To display the required pivot table on the new worksheet. Select the below-specified values, “date, sales, and week” entries. After that in the rows, section add the week and date. In the values section, add “Sum of sales”, and other required parameters as specified below −
Consider the final obtained pivot table structure −
This article briefs users on three ways to group the week's data by using the pivot table in Excel. Two examples allow the user to group the data, while the third example allows the user to use the helper method to process the same data.
Kickstart Your Career
Get certified by completing the courseGet Started