Reputation: 41
Say I want to find the ten most common things in a list. Crystal reports allows you to do this easily one by one with the Nthmostfrequent function. I am curious if we can do this a bit more efficiently say using a for loop..
I tried
local numbervar i;
local stringvar result;
local stringvar result = nthmostfrequent(i,{ticket.diagnosis});
for i :=1 to 10 do
(
nthmostfrequent(i,{ticket.diagnosis});
i := i+1;
);
result;
But it doesn't work saying a number is expected at i in the formula.
Edit: thinking I also need to initialize an array to house the results? Any help is very much appreciated!
Upvotes: 1
Views: 20253
Reputation: 7287
Your formula has a few issues. Most notably:
i
before it is initialized.NthMostFrequent()
isn't having its results saved anywhere. You're right in that you'll need to use an array to save your values.Try this instead
local numbervar i;
local stringvar array result;
redim result [10];
for i :=1 to 10 do
(
result[i]:=nthmostfrequent(i,{ticket.diagnosis})
);
//A formula cannot evaluate to an array. This collapses the array into a string
join(result, ', ')
EDIT: It appears that NthMostFrequent()
will NOT accept a variable for its first parameter value; it must be passed an explicit integer. This method won't work.
Upvotes: 0