Excel Formula to Group Products by Date and Count Limit
Question details
Find an Excel solution to group items into categories based on multiple conditions, including a maximum item count of 50 and a maximum date gap of 45 days.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Organizing products into photoshoot batches based on department, fit, and readiness dates to maximize batch sizes and reduce photography costs.
- Observed behavior
- The user needs to dynamically calculate batch assignments and determine the latest ready date for each batch using strict grouping prioritization rules.
Because this grouping involves overlapping conditions like maximum product limits and specific date windows, ensure your dataset is sorted chronologically by 'Ready Date' within each 'Department' and 'Fit' before applying formulas.
Use Helper Columns and Conditional Formulas
Break down complex grouping logic into manageable helper columns using standard functions like IF, COUNTIFS, and MAXIFS to assign batches and calculate dates.
A single massive array formula can be difficult to maintain. Using helper columns allows you to calculate the running total of products and track the date differences step-by-step.
Select your entire dataset, go to the Data tab, click Sort, and add levels to sort by Department (A to Z), Fit (A to Z), and finally Ready Date (Oldest to Newest).
Insert a new column named 'Running Count'. Use a COUNTIFS formula to count the number of products that share the same Department and Fit, resetting the count to 1 every time it reaches 50.
Add another helper column to calculate the difference between the current row's Ready Date and the first Ready Date of the current batch. Use an IF statement to trigger a new batch ID if the difference exceeds 45 days.
In your final result column, use the MAXIFS function to look at the assigned Photoshoot ID and return the latest (maximum) Ready Date for all products sharing that ID.

Process the Grouping Using Power Query
Power Query is highly effective for sequential grouping, allowing you to use custom index columns and conditional logic without cluttering your spreadsheet with formulas.
Automate Grouping Logic with a VBA Macro
For absolute precision over looping, limits, and date gaps, a VBA script can process the rows from top to bottom and output the exact photoshoot assignments automatically.
Organize Complex Data Effortlessly with WPS Spreadsheet
Whether you choose to use advanced dynamic array formulas, multi-condition helper columns, or custom VBA macros, WPS Spreadsheet provides all the tools you need to solve complex grouping challenges quickly.
- 1. Open your dataset in WPS Spreadsheet: Launch WPS Office and open your product data file. Ensure your data is organized into clear columns.
- 2. Sort your data properly: Navigate to the Data tab and use the Custom Sort feature to arrange your rows by Department, Fit, and Date.
- 3. Apply advanced formulas: Use WPS Spreadsheet's built-in formula suggestions to insert COUNTIFS and IF statements for your conditional grouping.
- 4. Calculate the final batch date: Use the MAXIFS function to automatically pull the latest date for each assigned photoshoot batch.

Frequently Asked Questions
How do I limit a running count to a specific number in an Excel formula?
You can use a combination of the IF and MOD functions, or reset a COUNTIFS formula. For example, if you want a counter to reset at 50, you can use a formula that checks if the previous row's count is 50; if true, it resets to 1, otherwise it adds 1 to the previous row.
Can I use MAXIFS to find the latest date in a specific group?
Yes, MAXIFS is perfect for this. The syntax is =MAXIFS(Date_Range, Group_ID_Range, Specific_Group_ID). This will look at all rows assigned to a specific group and return the most recent date.
What is the best way to group dates into ranges in spreadsheets?
If the date ranges are fixed (like months or quarters), a Pivot Table is the easiest method. However, for rolling date windows (e.g., items within 45 days of each other), you must sort the data chronologically and use helper columns with subtraction formulas to measure the gap between dates.




