A possible solution employing PyQGIS.
Let's assume there is a point layer called 'Layer_B' with its attribute table, see image below.

Case 1 without grouping
when a new "id" has to be assigned in a range of each attribute field
Proceed with Plugins > Python Console > Show Editor and paste the script below
from PyQt5.QtCore import QVariant
fieldname = "info" #a field which is used as an aggregating factor
newfieldname = "newid" #a new field that will maintain new ids
layer = iface.activeLayer()
idx = layer.dataProvider().fieldNameIndex(fieldname)
if newfieldname not in layer.fields().names():
pr = layer.dataProvider()
pr.addAttributes([QgsField(newfieldname, QVariant.Int)])
layer.updateFields()
req = QgsFeatureRequest()
req = req.addOrderBy(fieldname)
attr_old = None
with edit(layer):
for feat in layer.getFeatures(req):
attr = feat.attributes()[idx]
if attr == attr_old:
i += 1
else:
i = 1
feat[newfieldname] = i
layer.updateFeature(feat)
attr_old = attr

Press Run script
and get the output that will look like

P.S. Many thanks to @J.Monticolo
Case 2 with grouping
when a new "id" has to be assigned whenever the value in another attribute field changes
Proceed with Plugins > Python Console > Show Editor and paste the script below
from PyQt5.QtCore import QVariant
fieldname = "info" #a field which is used as an aggregating factor
newfieldname = "newid" #a new field that will maintain new ids
layer = iface.activeLayer()
idx = layer.dataProvider().fieldNameIndex(fieldname)
list_attributes = []
for feat in layer.getFeatures():
list_attributes.append(feat.attributes()[idx])
list_attributes = list(set(list_attributes))
dct = {list_attributes[i]: i + 1 for i in range(len(list_attributes))}
if newfieldname not in layer.fields().names():
pr = layer.dataProvider()
pr.addAttributes([QgsField(newfieldname, QVariant.Int)])
layer.updateFields()
with edit(layer):
for feat in layer.getFeatures():
attr = feat.attributes()[idx]
for key, value in dct.items():
if attr == key:
feat[newfieldname] = value
layer.updateFeature(feat)

Press Run script
and get the output that will look like

References: