Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

drminaker
New Contributor III

Combing two functions in load script (trim and replace)

Hi,

I'm trying to clean up a field and need to apply two functions in the load script. I've read through several other discussion posts and just can't seem to get the right syntax for this to work.

These are the two functions that I'd like to combine (both work as expected on their own). Any help is much appreciated.

If(Len(Trim(Instructor_Name)) > 0, Instructor_Name, 'None Specified') as [Instructor name],     //Replaced blanks with text

Replace (Instructor_Name,'  ',' ') as [Instructor name],    //Removes extra spaces between instructor names

Thanks in advance!

R.

1 Solution

Accepted Solutions
MVP
MVP

Re: Combing two functions in load script (trim and replace)

May be this

If(Len(Trim(Instructor_Name)) > 0, Replace (Instructor_Name,'  ',' '), 'None Specified') as [Instructor name]

7 Replies
MVP
MVP

Re: Combing two functions in load script (trim and replace)

May be this

If(Len(Trim(Instructor_Name)) > 0, Replace (Instructor_Name,'  ',' '), 'None Specified') as [Instructor name]

Re: Combing two functions in load script (trim and replace)

Hi Ryan, you can use Trim to remove the extra spaces:

If(Len(Trim(Instructor_Name)) > 0, Trim(Instructor_Name), 'None Specified') as [Instructor name]

MVP
MVP

Re: Combing two functions in load script (trim and replace)

it seems that the OP is looking to making double space into single space.....but I might be wrong...

Re: Combing two functions in load script (trim and replace)

It was just to give an idea, the comments says "Removes extra spaces between instructor names" but the code will only work if there are exactly two spaces, not three or more.

drminaker
New Contributor III

Re: Combing two functions in load script (trim and replace)

Sunny, thanks so much. I was trying to add the Replace before/after the Trim, not combining the two as you've done, which is obviously why I didn't work.

R.

drminaker
New Contributor III

Re: Combing two functions in load script (trim and replace)

Thanks Ruben! I was trying to remove cases where people's names had an accidental double space between first and last. My first attempt at solving this was with Trim, but realized I couldn't use it to remove extra spaces inside a string.

R.

Re: Combing two functions in load script (trim and replace)

True, I don't know when I started to think that it removes spaces in the middle.