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.
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)))

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With