zayn_mir
=IF(RIGHT(C2,3)="csv",IF(MOD(SUMPRODUCT(N(RIGHT($C$2:C2,3)="csv")),5)=0,"Agent ""IENT(SUMPRODUCT(N(RIGHT($C$2:C2,3)="csv")),5),"Agent ""IENT(SUMPRODUCT(N(RIGHT($C$2:C2,3)="csv")),5)+1),IF(RIGHT(C2,3)="abc",IF(MOD(SUMPRODUCT(N(RIGHT($C$2:C2,3)="abc")),5)=0,"Agent ""IENT(SUMPRODUCT(N(RIGHT($C$2:C2,3)="abc")),5),"Agent ""IENT(SUMPRODUCT(N(RIGHT($C$2:C2,3)="abc")),5)+1),IF(RIGHT(C2,3)="usa",IF(MOD(SUMPRODUCT(N(RIGHT($C$2:C2,3)="usa")),5)=0,"Agent ""IENT(SUMPRODUCT(N(RIGHT($C$2:C2,3)="usa")),5),"Agent ""IENT(SUMPRODUCT(N(RIGHT($C$2:C2,3)="usa")),5)+1),IF(RIGHT(C2,3)="zzz",IF(MOD(SUMPRODUCT(N(RIGHT($C$2:C2,3)="zzz")),5)=0,"Agent ""IENT(SUMPRODUCT(N(RIGHT($C$2:C2,3)="zzz")),5),"Agent ""IENT(SUMPRODUCT(N(RIGHT($C$2:C2,3)="zzz")),5)+1),IF(RIGHT(C2,3)="edv",IF(MOD(SUMPRODUCT(N(RIGHT($C$2:C2,3)="edv")),5)=0,"Agent ""IENT(SUMPRODUCT(N(RIGHT($C$2:C2,3)="edv")),5),"Agent ""IENT(SUMPRODUCT(N(RIGHT($C$2:C2,3)="edv")),5)+1),"")))))
Both formulas work flawlessly and as expected in my sheet. I've expanded the nested IF formula for 5 domains and it returns the intended results. Below i've highlighted the initial criteria of each IF statement for explanation.
=IF(RIGHT(C2,3)="csv" ,IF(MOD(SUMPRODUCT(N(RIGHT($C$2:C2,3)="csv")),5)=0,"Agent ""IENT(SUMPRODUCT(N(RIGHT($C$2:C2,3)="csv")),5),"Agent ""IENT(SUMPRODUCT(N(RIGHT($C$2:C2,3)="csv")),5)+1),
IF(RIGHT(C2,3)="abc" ,IF(MOD(SUMPRODUCT(N(RIGHT($C$2:C2,3)="abc")),5)=0,"Agent ""IENT(SUMPRODUCT(N(RIGHT($C$2:C2,3)="abc")),5),"Agent ""IENT(SUMPRODUCT(N(RIGHT($C$2:C2,3)="abc")),5)+1),
IF(RIGHT(C2,3)="usa" ,IF(MOD(SUMPRODUCT(N(RIGHT($C$2:C2,3)="usa")),5)=0,"Agent ""IENT(SUMPRODUCT(N(RIGHT($C$2:C2,3)="usa")),5),"Agent ""IENT(SUMPRODUCT(N(RIGHT($C$2:C2,3)="usa")),5)+1),
IF(RIGHT(C2,3)="zzz" ,IF(MOD(SUMPRODUCT(N(RIGHT($C$2:C2,3)="zzz")),5)=0,"Agent ""IENT(SUMPRODUCT(N(RIGHT($C$2:C2,3)="zzz")),5),"Agent ""IENT(SUMPRODUCT(N(RIGHT($C$2:C2,3)="zzz")),5)+1),
IF(RIGHT(C2,3)="edv" ,IF(MOD(SUMPRODUCT(N(RIGHT($C$2:C2,3)="edv")),5)=0,"Agent ""IENT(SUMPRODUCT(N(RIGHT($C$2:C2,3)="edv")),5),"Agent ""IENT(SUMPRODUCT(N(RIGHT($C$2:C2,3)="edv")),5)+1),"")))))