rsort not working
Hi all -
rsort is leaving out the first item in my array, see pic.
Forumla2 is the the regular sort order and Formula is the reverse sort. As you can see 7 stays in the first position.
Here is my code:
let curRec := this;
let x := ((select TeamResults)[Location = curRec.Location] order by SumPnts);
let conX := concat(x.SumPnts);
let xArray := split(conX, ",");
let rsArray := rsort(xArray);
rsArray
Thanks for any help.
7 replies
-
Hi Fred,
I think the rsort formula can be simplified to this...
let curRec := this;
rsort((select TeamResults)[Location = curRec.Location] order by SumPnts)
-
Sadly it doesn't. This change brings up an empty formula.
rsort only works on arrays, thus the many steps to turn the results into an array. I can probably shorten some steps, but i find it helpful to break the steps out.
-
The result of a select statement is an array. You can use a select statement inside the
count()
function to see how many items are in the array. I didn't use a location field in my test database... -
I guess my coding was off. I can shorten the code and leave out the concat and split.
When I do this:
let curRec := this;
rsort(select TeamResults)[Location = curRec.Location].SumPntsI get this:
If I do this:
let curRec := this;
let x := (select TeamResults)[Location = curRec.Location];
rsort(x.SumPnts)then I get the desired results:
So thanks for the help.
-
I just realized my mistake in the formula 7. I forgot the ( ) for the rsort. Once I add that in, all is well. Thanks.
-
Hi Fred
I wanted to understand why your initial code was not working and I have found out why. By concatenating and then splitting you introduced a leading space into each element except the first one. So rather than having
7
17
18
...
55
you had
7
17
18
...
55
rsort this and 7 has the largest value and will remain at the top.
Regards John
-
Hi John,
I completely overlooked that. Even though spaces were added, that's not why it's being sorted that way. When the values were concatenated, they were converted to text and then were sorted by ASCII value instead of numeric value.
Regards
Content aside
- 3 yrs agoLast active
- 7Replies
- 402Views