Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
lucasx15
Contributor III
Contributor III

GetFieldSelections with IF and Replace

Hi, guys!

Hello everyone, I can't use GetFieldSelections in an IF in script? I did this in the code however, it is not working.

=IF(Replace(GetFieldSelections(WORKSHIFT),'Night 1', 'This is Work shift 1',
IF(Replace(GetFieldSelections(WORKSHIFT),'Morning', 'This is Work shift 2'))))

 

Labels (1)
1 Solution

Accepted Solutions
edwin
Master II
Master II

if what you want to do is replace the shift code with some description and you only have 2 values you can use it in cascade:

Replace(
   Replace(
      GetFieldSelections(WORKSHIFT),
      'Morning', 
      'This is Work shift 2'
   ),
   'Night 1', 
   'This is Work shift 1'
)

the result of the inner replace becomes the input to the outer one.

 

however, i would suggest a different way.  i would create an association between WORKSHIFT and a WORKSHIFT_DESC field.  where WORKSHIFT_DESC is obviously the description.  when workshift is selected, the descriptions are
=concat(distinct WORKSHIFT_DESC,',')  which will be the same result.  however, the advantage of this is you can have as many values for WORKSHIFT and you dont need to change your code.  that is, if tomorrow, a new value is added you will need 3 levels of replace.

this may not apply to you but at least you know there is an alternative for the future.

View solution in original post

3 Replies
edwin
Master II
Master II

if what you want to do is replace the shift code with some description and you only have 2 values you can use it in cascade:

Replace(
   Replace(
      GetFieldSelections(WORKSHIFT),
      'Morning', 
      'This is Work shift 2'
   ),
   'Night 1', 
   'This is Work shift 1'
)

the result of the inner replace becomes the input to the outer one.

 

however, i would suggest a different way.  i would create an association between WORKSHIFT and a WORKSHIFT_DESC field.  where WORKSHIFT_DESC is obviously the description.  when workshift is selected, the descriptions are
=concat(distinct WORKSHIFT_DESC,',')  which will be the same result.  however, the advantage of this is you can have as many values for WORKSHIFT and you dont need to change your code.  that is, if tomorrow, a new value is added you will need 3 levels of replace.

this may not apply to you but at least you know there is an alternative for the future.

lucasx15
Contributor III
Contributor III
Author

Thank you, Edwin!!! 

edwin
Master II
Master II

yw