Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Does function order matter when applying 2 to one field in the script?

Does the order of expressions matter when applying in the script? My original post I discovered that the text function was not working correctly when it was inside of the rtrim function. Qlikview seemed to ignore the fact that I was telling it to consider the field only as a string.

I went through the scripts and everywhere that I had rtrim(text(field)) I changed to text(rtrim(field)) and this seemed to work correctly so that it now did not combine values with a leading 0.

However I am now having problems with fields with spaces. I have Verbatim turned on (I only need to keep leading spaces and drop trailing spaces hence the rtrim() function)

It now seems like it is ignoring the rtrim function. This is causing a lot of my formulas to calculate incorrectly giving me incorrect data. I know this is the cause because I tested the field in the formula by applying rtrim() around it.

Is there anything I can do here? Qlikview seems to only recognize the outside function and I am going crazy trying to figure this one out.

11 Replies
MayilVahanan

Hi

Text() function gives result in string format only..

text( A ) where A=1234 returns:

   

Result

String

1234

Number

rtrim() function

rtrim(s )

Returns the string s trimmed of any trailing spaces.

Example:

rtrim ( ' abc' ) returns ' abc'

rtrim ( 'abc ' ) returns 'abc'

Hope it helps

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
Not applicable
Author

OK, so wouldn't the function rtrim remove any spaces to the right, and then wrapping that in Text() cause the result to be a string format only? Why would

Load

text(rtrim(field)) as field

from file;

not work, but doing this would work?:

Load

text(rtrim(field)) as field

from file;

Load

rtrim(field) as field

resident file;

drop table file;

I guess a better question would be, at what point does Qlikview format a field as a number vs as a string? If I am loading an entire table to be stored into a QVD before I do any alterations or links in the current dashboard, what would be the best way to format the data so that I would not need to do repeat functions or store incorrect data into the QVD itself? My only requirements are that the nvarchar fields be treated only as strings, even if they contain only numerical data. and that all nvarchar fields retain leading spaces.

I am just completely lost on the logic that allows the following:

(All inside of a straight table with [Segment 1] as the dimension

//Only works if I apply ONLY rtrim([Segment 1]) as [Segment 1] in the script level , or if I do NOT apply the Text() function at all, OR if I select only value 700400 from that field.

sum(if([Segment 1]='700400',[Credit Amount]+[Debit Amount]))

//Works no mater what I do in the script. Only works if [Segment 1] is the dimension which makes sense.

if([Segment 1]='700400',sum([Credit Amount]+[Debit Amount]))

//Works all the time.

sum({<[Segment 1]={'700400'}>}[Credit Amount]+[Debit Amount])

I know it would work for me to switch all my expressions to use set analysis. That is not my question or issue. I need to know how the data is effected when it is being stored into the QVD's and how linking between tables are being effected when I resident load from the first load of a table. This is not a simple "The function works all problems are solved" issue.