Author Topic: Counting multi-entry fields  (Read 1936 times)

tangotonyb

  • Jr. Member
  • **
  • Posts: 115
I'd like to find a function to express the number of entries in a multi-entry field.

E.g. The field has "ABC; DEF; JKL" content.

If I use the formula $If($Contains(<MyField>,";"),"Yes","No"), it correctly returns Yes for all the files with multiple entries, and no for files with either no entry or a single value.

What I'd like to do is actually count them though
SO that an empty field returned 0, and the example above: 3.

Any suggestions?

redwing

  • Guest
This will count up to 5 and show "m" for more.

Code
$If($RxReplace(<Artist>,"[^;]",)="",1,$If($RxReplace(<Artist>,"[^;]",)=";",2,$If($RxReplace(<Artist>,"[^;]",)=";;",3,$If($RxReplace(<Artist>,"[^;]",)=";;;",4,$If($RxReplace(<Artist>,"[^;]",)=";;;;",5,m)))))

tangotonyb

  • Jr. Member
  • **
  • Posts: 115
I take my hat off to you sir.

I was looking at something similar using a combination of If's and Splits, but the expression would have been about 10 times longer.

Regex replace all non-separating characters - GENIUS!

Many thanks!

tangotonyb

  • Jr. Member
  • **
  • Posts: 115
You also read my mind, because I only want to count up to 5 :)

tangotonyb

  • Jr. Member
  • **
  • Posts: 115
Ooh - I've improved on it though with a guess at an undocumented function: $Len

$Len($RxReplace(<MyField>,"[^;]",))

Couldn't have done it without that RegEx idea though :)

redwing

  • Guest
Great improvement!
This will be more accurate:

Code
$Add($Len($RxReplace(<Artist>,"[^;]","")),1)
And those functions are supported by Additional Tagging Tools plugin.

tangotonyb

  • Jr. Member
  • **
  • Posts: 115
The only issue with that is that it will count no entries in the field as 1 also.

The final solution is

$If($Len(<FieldName>)>0,$Add($Len($RxReplace(<FieldName>,"[^;]","")),1),0)

redwing

  • Guest