How to Alternate Row Colors by Group ID with Conditional Formatting
Question details
The user wants to visually group records by applying alternate row colors based on a specific Team ID, ensuring that all rows sharing the same ID have the same background color.

- Product
- Spreadsheet
- Device & OS
- not provided
- Scenario
- Formatting a large dataset to make groups of related records visually distinct from one another using dynamic color banding.
- Observed behavior
- The goal is to have the row background color automatically change only when the value in the Team ID column changes.
Ensure your dataset is sorted by the Team ID column so that all identical IDs are grouped together before applying the conditional formatting rules.
Use XMATCH and UNIQUE Functions (Modern Spreadsheets)
This is the most efficient method for newer spreadsheet versions, dynamically applying formatting based on the occurrence of unique IDs.
This formula checks the position of the current row's ID against a unique list of all IDs in the specified range. By extending the range (e.g., to row 1000), you ensure the formatting applies as you add new data.
Highlight the entire dataset where you want the formatting applied, for example, cells A3:G1000.
Navigate to the 'Home' tab and click on 'Conditional Formatting', then select 'New Rule'.
Choose the option to use a formula to determine which cells to format. Enter the following formula: =MOD(XMATCH($B3,UNIQUE(TOCOL($B$3:$B$1000,1))),2)=1 (assuming column B contains your Team IDs and your data starts at row 3).
Click 'Format', go to the 'Fill' tab, choose your desired background color, and click 'OK' to apply the rule.

Use FREQUENCY Function (Legacy Compatibility)
If you are using an older version of spreadsheet software that does not support XMATCH or UNIQUE, this array-based formula is a reliable alternative.
Visually Group Your Data with WPS Spreadsheet
WPS Spreadsheet provides robust conditional formatting tools that fully support complex array formulas, helping you organize and visualize your grouped data effortlessly without any lag.
- 1. Open Your Dataset: Launch WPS Spreadsheet and open the document containing your team data.
- 2. Access Conditional Formatting: Highlight your data range, click the 'Home' tab, and select 'Conditional Formatting'.
- 3. Apply Your Rule: Click 'New Rule', paste your grouping formula, and customize your row colors to instantly transform your table.

Frequently Asked Questions
How can I apply a second color instead of leaving alternating rows white?
To alternate between two specific custom colors, create a second conditional formatting rule for the same data range. Use the exact same formula but change the end from =1 to =0, and choose your second color in the formatting options.
Why are my rows not grouping together properly?
These conditional formatting formulas assign colors based on the sequential occurrence of unique values. If your data is not sorted by the Team ID column, identical IDs might be separated, which breaks the visual grouping block. Always sort your data by the grouping column first.
Will this formatting automatically apply if I add a new team to the bottom of the list?
Yes, provided your formula references a range larger than your current dataset (e.g., $B$1000). Alternatively, if you format your dataset as a Table, the conditional formatting rules will automatically extend as new rows are added.




