Counting the largest number of multi-values in X no. of cols
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Does it have to be 20 columns, or can you get them as one column? If not, assemble a field-mark delimited dynamic array containing the 20 columns. Apply the Counts() function to return an equivalent dynamic array of the number of value marks in each field (you may need to convert to a non-delimiter character for this). Apply the Maximum() function to get the highest count. Use Locate to find the first occurrence of this in the counts dynamic array. Create a business rule about how to handle more than one field having the same maximum count.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Does it have to be 20 columns, or can you get them as one column? If not, assemble a field-mark delimited dynamic array containing the 20 columns. Apply the Counts() function to return an equivalent dynamic array of the number of value marks in each field (you may need to convert to a non-delimiter character for this). Apply the Maximum() function to get the highest count. Use Locate to find the first occurrence of this in the counts dynamic array. Create a business rule about how to handle more than one field having the same maximum count.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
What i meant was a variable number of columns....ray.wurlod wrote:Does it have to be 20 columns, or can you get them as one column? If not, assemble a field-mark delimited dynamic array containing the 20 columns. Apply the Counts() function to return an equivalent dynamic array of the number of value marks in each field (you may need to convert to a non-delimiter character for this). Apply the Maximum() function to get the highest count. Use Locate to find the first occurrence of this in the counts dynamic array. Create a business rule about how to handle more than one field having the same maximum count.
so you mean to say Count(col1:col2:col3:...:20,@FM)
or is it better to get maximum(col1:col2:col3....col20)?
Thanks
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
The following is the result that i deployed as a server routine:ray.wurlod wrote:If you want the maximum count, no.
Figure out your actual requirement and deploy the appropriate functions.
I've suggested the most likely.
Function TestCompare<Arg1>
MaxCount = 0
PosOfMax = 0
NArgs = dcount<Arg1,"|">
For i = to Nargs
ThisArg = Field(Arg1,"|",i)
ThisCount = DCOUNT(ThisArg, @VM)
if ThisCount > MaxCount then
MaxCount = ThisCount
PosOfMax = i
End
Next i
Ans = Field(Arg1,"|",PosOfMax)
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact: