Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Reverse a value

Hi,

Im trying to take a value eg. 123456789 and get a new value with the same digits but backwards ( so ill be getting 987654321). Does anyone know how to do this because ive tried using replace(index but im not successful.

Any help is appreciated, thanks in advance

1 Solution

Accepted Solutions
hector
Specialist
Specialist

Hi, i've made this macro



Function reverse(t)
r = ""
For i = len(t) to 1 step -1
r = r & mid(t,i,1)
next
reverse = r
end Function


And you can call it from the script



LOAD
*,
reverse(F1) as F1_reverse
INLINE [
F1
123456789
];


It works for me, can you try it?

Rgds

View solution in original post

8 Replies
hector
Specialist
Specialist

Hi, i've made this macro



Function reverse(t)
r = ""
For i = len(t) to 1 step -1
r = r & mid(t,i,1)
next
reverse = r
end Function


And you can call it from the script



LOAD
*,
reverse(F1) as F1_reverse
INLINE [
F1
123456789
];


It works for me, can you try it?

Rgds

Not applicable
Author

Thanks for the step in the right direction, yeah ive got it working however I trying use it for a field so when i use a field, the field name appears backwards instead of the value.

hector
Specialist
Specialist

Hi again

Please note that reverse(F1) is different of reverse('F1')

For the first case, the function will reverse the value of the field F1 and you can put an alias to name it, and in the second one it's going to reverse the text "F1", so the function will return "1F"

is this your problem?

Rgds

Not applicable
Author

Hi,

Basically in ur example you have used 123456789 as just plain text, im trying to change that 123456789 to a field from a qvd. so basically what my code shows

LOAD





*

,

reverse

(F1) as

F1_reverse

INLINE

[ FI
CI_PER.PER_ID

; but the function is taking the text CI_PER.PER_ID and changing it to DI_REP.REP_IC instead to taking the value of that field





hector
Specialist
Specialist

Hi

The inline table was just an example for the functionallity and it's application, you need to use the function inside the load of your QVD file, i mean


Load
Field1,
Field2,
reverse(Field2) as Reverse_Field2
....
From QvdFile.qvd (qvd);


You can use the function reverse in the same way you use other qlikview functions like year(), month(), applymap() etc

Rgds

Not applicable
Author

Yeah I got that working now, thanks alot for your help. Your a legend

hector
Specialist
Specialist

No problem 😉

greetings

Anonymous
Not applicable
Author

Hi,


Could you indicate how to declare this script inside the load statement of QV?

I am trying to have it in a include file, without much success.

Thanks,


Antoine