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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
adiarnon
Creator III
Creator III

STRING FUNCTION

HI,

is there any function that change the order of the chars -

like from '1q2w3e' to 'e3w2q1'

or - 'abcd' to 'dcba'

please help.

5 Replies
its_anandrjs
Champion III
Champion III

Hi,

I don't thing there is reversing function available but you can do this way

=mid(Chr,len(Chr),1) & mid(Chr,len(Chr)-1,1) & mid(Chr,len(Chr)-2,1) & mid(Chr,len(Chr)-3,1) & mid(Chr,len(Chr)-4,1) & mid(Chr,len(Chr)-5,1)

Hope this helps

Thanks & Regards

stevedark
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi there,

In what context do you want to do this?

If it's a single variable in a load script you could loop from 1 to the length of the string and build it backwards in your load script.

If it is a field in a LOAD statement then you could build the loop in a Macro and then that can be called in-line in the load statement.  Note that macros are generally considered a 'last resort' rather than anything else.

If it is in the front end you could do it in a variable that receives a parameter.  You could not do a loop here, so the syntax would need to be similar to Anand's example.  This would mean your function would have a maximum number of characters it could deal with.

If the field is coming from a SQL database you may find that building the function in SQL is more efficient than doing the same thing in QlikView.

It may be possible to use the Variable with a parameter on a field in a load script - but I would not like to say that for sure.

If you can provide the context I may be able to provide further pointers.

Cheers,

Steve

maxgro
MVP
MVP

perhaps here

Reverse string

adiarnon
Creator III
Creator III
Author

hi,

its a dimension in a pivot table.

in the scheme the content of this field is reversed.

and i want that in my table it will be straight that the uses can read it...

stevedark
Partner Ambassador/MVP
Partner Ambassador/MVP

In that case, your best bet is to create a variable called vReverse and populate it with this code:

='mid($1, len($1) - 0, 1) & mid($1, len($1) - 1, 1) & mid($1, len($1) - 2, 1) & mid($1, len($1) - 3, 1) &

  mid($1, len($1) - 4, 1) & mid($1, len($1) - 5, 1) & mid($1, len($1) - 6, 1) & mid($1, len($1) - 7, 1) &

  mid($1, len($1) - 8, 1) & mid($1, len($1) - 9, 1) & mid($1, len($1) - 10, 1) & mid($1, len($1) - 11, 1) &

  mid($1, len($1) - 12, 1) & mid($1, len($1) - 13, 1) & mid($1, len($1) - 14, 1) & mid($1, len($1) - 15, 1)'

You can then call a Calculated Dimension in your Pivot with the following:

=$(vReverse(MyField))

It would be better to reverse the field in the load script and have two versions of the field.  I couldn't get this to work using the variable above in a quick test, but in that instance you could just use the code above without the variable - replacing $1 with the name of your field.

Hope that helps.

Steve