Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Save $650 on Qlik Connect, Dec 1 - 7, our lowest price of the year. Register with code CYBERWEEK: Register
cancel
Showing results for 
Search instead for 
Did you mean: 
p0cket0m
Contributor III
Contributor III

Automation: How to invert List item order or loop from the last item to the first item

Lets say we have a custom list variable with these items:

A1
X2
G3
S4

I want to loop over the list in descending item position order:

S4
G3
X2
A1

Applying the sortdesc formula on the list does not what I want

X2
S4
G3
A1

How to sort desc by list item position? Is this even possible or are there any other workarounds?

Labels (3)
1 Reply
Shai_E
Support
Support

Hi @p0cket0m 

One way is to use the Custom Code block, it ingests the list and then you can use one of the programing languages lets say node js to use the reverse array method on the array.

Then console log the the stringified array value, that will in turn let you use the values from the custom code block outside of it in other blocks down the line.

I am also sure there is a less cleaner way to do this with simply a loop, by storing the length of the array in a variable and subtracting 1 from it on each iteration of the loop, then using that as an index to access the array item in formula mode.

Best Regards