Here comes a classic need in Power Query which to is Change Index at discontinuity. Sometimes, you need to insert index but change is needed at when value in left column changes. Have a look at below picture to understand what I am talking about.
First 2 entries have index of 1. Then A changes to B, hence index will change to 2. At C, index will change to 3 and so on.
Step 1 – Select the column over which indexing has to be performed – Transform tab – Group By – Choose Operation as All Rows
Step 2 – Add Column – Index Column – From 1
Step 3 – Click on double pointed arrow (on right side of Count column) – Uncheck Use original column name as prefix
Step 4 – Select Data.1 column – Right click on header – Remove
That's it.
For persons who prefer one step solution, they can put following function after loading the table to Change Index at discontinuity
= Table.RemoveColumns(Table.ExpandTableColumn(Table.AddIndexColumn(Table.Group(Source, {"Data"}, {{"Count", each _, type table}}), "Index", 1, 1), "Count", {"Data"}, {"Data.1"}),{"Data.1"})
The Excel file related to this tip can be downloaded from PQ_TT4.Power Query M function reference – PowerQuery M | Microsoft Docs