Home > Software engineering >  reset back to zero if value found ar
reset back to zero if value found ar

Time:12-30

i have got an formula on excel whereby it calculate and add all the "s" from a range however is there anyway also to minus same value calculated if "ar" found within the same range

below it is the formula that counts all the "s" and add the result in to cell number B6

=SUMPRODUCT(LEN(C3:C49978)-LEN(SUBSTITUTE(C3:C49978,"s","")))

many thanks in advance

CodePudding user response:

=SUMPRODUCT((LEN(C3:C49978)-LEN(SUBSTITUTE(C3:C49978,"s","")))*(LEN(C3:C49978)=(LEN(SUBSTITUTE(C3:C49978,"ar",""))))) Using the same kind of logic you used I added a condition where the only from values that do not contain "ar" the occurance of s is counted otherwise it's ignored.

CodePudding user response:

Case 1 = (C): total count

Case 2

=SUMPRODUCT(LEN(SUBSTITUTE(C3:C50,"ar","."))-LEN(SUBSTITUTE(C3:C50,"s","")))

Case 2: = (D): count 's' less count 'ar'

Notes

• Suspect you're after case 1 - interested to know, but you have both cases anyway

• Assumes case-sensitive (so 'S' and 'AR' excluded from calcs. To illustrate minor amendment to your function to count 'S' and/or 's' could modify as follows♣ :

=LET(x_,LOWER(C2:C50),SUMPRODUCT(LEN(x_)-LEN(SUBSTITUTE(x_,"s",""))))

Case insensitive variant of given function (A, count 's &/or S')

Just for fun - an overcomplex variant of this (not recommended, hardly 'parsimonious' as is your function♣):

=SUM(1*(LOWER(LET(x_,TEXTJOIN("",1,C3:C9),FILTERXML("<x><y>"&MID(x_,SEQUENCE(LEN(x_),1,1,1),1)&"</y></x>","//y")))="s"))

Over-complex alternative - case: insensitive count 's' &/or 'S'

♣ requires Office 365 compatible version of Excel

  • Related