For not having 0's in your field, the expression in the field-calculator will look like:
array_find( array_distinct( array_agg("Name")), "Name") +1
where Name is the attribute column name (thank you @MrXsquared).
In addition:
If you have a null value in the original attribute-collumn: Name use the coalesce() function. Your expression will look like:
coalesce( array_find( array_distinct( array_agg("Name")), "Name") +1,0 )
where the last 0 after the , will become the value of the original null value from the Name attribute column. So if you like, you can also write a number like 999 after the last ,