Large number sort from aggregate
Application Type
Reactive
Platform Version
11.8.4 (Build 29614)

Sorting large numbers from an aggregate via TableSort is only sorting by the first integer.


For example from largest to smallest: 960,000 is sorting above 20,000,000, which appears to be sorting the first integer 9 > 2 and not the entire number. Obviously should be 20,000,000 then 960,000.


I know how to resolve this in javascript by using .sort() and passing a compare function shown below:

let nums = [960000, 20000000]

nums.sort(function (a, b) {
return b-a;
})


which will return [20000000, 960000]


But not certain how to do so in Outsystems.


Any help is much appreciated, thank you!

mvp_badge
MVP
Solution

If you want to sort numeric make sure to sort on an attribute with numeric datatype. 

mvp_badge
MVP

Hi,

If you sort on an entity attribute with data type integer or numeric then 960000 will be listed before  20000000 if you sort ascending.

Your observation on the sort result can only be valid if the data is stored in an attribute of data type text.

Regards,

Daniel 

Hi Daniel,


Thanks for your reply! Initially, I was converting the text to integer, however I just reverted it back to text and it still is sorting by the first integer. I've attached an image of the aggregate with the specific field highlighted. Although I should mention I'm using a data type mask forge component which takes a string of numbers and masks it as currency i.e. $96,000. So when displaying the data from the aggregate I also tried removing the dollar sign and commas via the expression below in an attempt to sort it correctly, but it is indeed saved as text in aggregate in the end.


Substr(Replace(GetProjectsByTeamMember.List.Current.DealSize, ",", ""), 1, Length(GetProjectsByTeamMember.List.Current.DealSize))
2022-05-31 13_52_40-TechDealsDashboard (Tech Deals Dashboard) - lowenstein-dev.outsystemsenterprise..png

mvp_badge
MVP
Solution

If you want to sort numeric make sure to sort on an attribute with numeric datatype. 

Can I sort on a text data type that's converted to integer via TextToInteger()? Or the attribute itself has to initially be numeric? Because that wasn't working either. 

Ok so for anyone else if it's not obvious, what Daniel mentioned is literally correct. The attribute itself has to be an integer, it doesn't matter if you convert the value to Integer. So I created a new attribute on my aggregate and for its value used the TextToInteger() function to convert the text attribute in question.


Thank you Daniel!

mvp_badge
MVP

Yes, sorting is done in and by the database, so you need the right value inside the database. In a SQL query, you can do the conversion in the ORDER BY, but you cannot do that in the aggregate editor (it only allows you to select an attribute for sorting). So creating a calculated attribute and sorting on that is indeed the solution.   

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.