# Batching sequential rows that are "like groups" with a formula

Options
✭✭✭✭✭✭

Here's what I want to do. Column A has values that I want to group by rows, as shown in Column B. So the first group of "x" rows is a "1", the second group of "y" rows is a "2", alternating as shown.

This is a lot of data so I can't have infinite helper columns.

## Best Answers

• ✭✭✭✭✭✭
Answer ✓
Options

Add the following columns:

Title: Row ID (system column Auto-Number)

Title: ROW# Formula: =MATCH([Row ID]@row, [Row ID]:[Row ID], 0)

Title: Value (Column A in your description)

Title: First Group Formula: =IF([ROW#]@row = 1, 1, IF(INDEX(Value:Value, [ROW#]@row - 1) = Value@row, 0, 1))

Title: Group Number Formula: =COUNTIFS([First Group]:[First Group], @cell = 1, [ROW#]:[ROW#], @cell <= [ROW#]@row)

• ✭✭✭✭✭✭
Answer ✓
Options

did you copy my formulas? Working perfectly on my end:

## Answers

• ✭✭✭✭✭✭
Answer ✓
Options

Add the following columns:

Title: Row ID (system column Auto-Number)

Title: ROW# Formula: =MATCH([Row ID]@row, [Row ID]:[Row ID], 0)

Title: Value (Column A in your description)

Title: First Group Formula: =IF([ROW#]@row = 1, 1, IF(INDEX(Value:Value, [ROW#]@row - 1) = Value@row, 0, 1))

Title: Group Number Formula: =COUNTIFS([First Group]:[First Group], @cell = 1, [ROW#]:[ROW#], @cell <= [ROW#]@row)

• ✭✭✭✭✭✭
Options

That's the direction I was heading -- the last column doesn't get me there, however. I tried to sum all the First Group at or prior to the current row with this formula: =SUMIF([First Group]:[First Group], [ROW#]:[ROW#] <= [ROW#]@row)

However, that just populated the column with the sum of every group (17).

• ✭✭✭✭✭✭
Answer ✓
Options

did you copy my formulas? Working perfectly on my end:

• ✭✭✭✭✭✭
Options

Must have been a syntax or cache issue. In the end I just updated the sumif to sumifs (below), that worked. I then went and retried yours, which worked as well. Thanks for the help!

=SUMIFS([First Group]:[First Group], [ROW#]:[ROW#], <= [ROW#]@row)

• ✭✭✭✭✭✭
Options

Curious why use the ROW# vs just the Row ID? I was able to get both to work.

• ✭✭✭✭✭✭
Options

ROW# will update even if you move around the rows...

• ✭✭✭✭✭✭
Options

Ah, got it. If I have a unique serial number for each line I can use that as well. Thanks!

• ✭✭✭✭✭✭
Options

Yes that would work