Power Query M code
let
Source = YourTable,
Grouped = Table.Group(Source, {"GroupColumn"}, {{"AllRows", each Table.AddIndexColumn(_, "IndexInGroup", 1, 1, Int64.Type), type table}}),
Expanded = Table.ExpandTableColumn(Grouped, "AllRows", Table.ColumnNames(Source) & {"IndexInGroup"})
in
Expanded