Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
umashankarus
Contributor III
Contributor III

Sort within a field

Hi Experts,

Have a field with set of numbers with a delimiter >>  ex: (1.4, 5.1, 5.35, 2.4)

Expected result after sort by descending - (5.35, 5.1, 2.4, 1.4)

Is there standard function to apply sort within a field

Thanks,

Umashankar

1 Solution

Accepted Solutions
jonathandienst
Partner - Champion III
Partner - Champion III

For example:

T_Start:

LOAD * Inline

[

ID| Field

1|  (1.4, 5.1, 5.35, 2.4)

2|  (0.8, 3.1, 2.35, 6.4)

] delimiter is ('|');

Result:

LOAD

    ID,

    '(' & Concat(Token, ', ', -Token) & ')' as Result // -Token will sort the tokens in descending order

Group by ID;

LOAD

    ID,

    Num(SubField(PurgeChar(Field, '()'), ',')) as Token   //subfield will return one row per token

Resident T_Start;


Capture.PNG

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein

View solution in original post

3 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

Something like this

LOAD

     ID,

     '(' & Concat(Token, ',', -Token) & ')' as Result // -Token will sort the tokens in descending order

Group by ID;

LOAD

     ID,

     SubField(PurgeChar(Field, '()'), ',') as Token   //subfield will return one row per token

FROM ....

ID shows how other fields should be handled. The Group By in the upper load should contain all fields except Token.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
jonathandienst
Partner - Champion III
Partner - Champion III

For example:

T_Start:

LOAD * Inline

[

ID| Field

1|  (1.4, 5.1, 5.35, 2.4)

2|  (0.8, 3.1, 2.35, 6.4)

] delimiter is ('|');

Result:

LOAD

    ID,

    '(' & Concat(Token, ', ', -Token) & ')' as Result // -Token will sort the tokens in descending order

Group by ID;

LOAD

    ID,

    Num(SubField(PurgeChar(Field, '()'), ',')) as Token   //subfield will return one row per token

Resident T_Start;


Capture.PNG

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
umashankarus
Contributor III
Contributor III
Author

Thanks Jon