Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel automatic numeration according to ID

Given following table:

No. ID
HA
PA
PA
PA
HA
PA
HA
PA
PA
HA

I would like to create a formula for the first column to create an automatic numbering where the main number always increments when ID="HA", and the secondary number always increments when ID="PA", like so:

No. ID
1 HA
1.1 PA
1.2 PA
1.3 PA
2 HA
2.1 PA
3 HA
3.1 PA
3.2 PA
4 HA

If it helps, what I have got so far is:

=IF(B2="HA",COUNTIF($B$2:B2,"HA"),CONCAT(A1,".",COUNTIF(INDIRECT("B"&XMATCH("HA",$B$2:B2)),"PA")))

As you can see I am struggling with the second part, maybe someone can help me out from here.

like image 465
pato Avatar asked Sep 06 '25 03:09

pato


1 Answers

With Microsoft-365 you may try SCAN() function.

=SCAN(0,B2:B11,LAMBDA(a,x,IF(x="HA",a+1,a)))+SCAN(0,B2:B11,LAMBDA(aa,xx,IF(xx="HA",0,aa+1)))/10

As per suggestion by @VBasic2008 in comment section, following formula is more simpler and elegant.

=SCAN(0,B2:B11,LAMBDA(a,x,IF(x="HA",INT(a)+1,a+0.1)))

enter image description here

like image 51
Harun24hr Avatar answered Sep 07 '25 19:09

Harun24hr