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: 
AmirMoha
Contributor III
Contributor III

Replace or remove part of string based on another column

Hi all, 

I'm really struggling here and I need help please

I have a column with Product names and in this column it has the product names plus the colour (ex; Blue, Black etc)

and I have another column that has the colours, 

in the product names column it has the colour name in two parts, at the first part and at the last part of the name, I want to keep the first part and remove the last part of the colour , examples are below

GIA | SILVER DIAMANTE SPIKE DETAIL HOOP EARRINGS SILVER

AURORA | LIGHT MOCHA ONE SHOULDER CAPE SLEEVE JUMPSUIT LIGHT MOCHA

I want to remove the highlighted parts of the colours but I am unable to do so as the spaces of the string are not the same ex; 5 spaces or 6, 

I have another column that has the colours 

I really appreciate your help

Labels (4)
1 Solution

Accepted Solutions
AmirMoha
Contributor III
Contributor III
Author

I have finally got this fixed,  with the below functions

LOAD *,
    Left(ProductName, Len(Trim(ProductName)) - Len(Trim(Colour))) as Product_name;

View solution in original post

3 Replies
MayilVahanan

Hi

Try like below


Mapcolor:
Mapping
Load *, '~'&Color&'~' as ReplaceValue Inline
[
Color
SILVER
LIGHT MOCHA
];

Temp2:
Load ProductName, Trim(Replace(Left(TempField, Index(TempField,'~', 3)), '~', '')) as ExpectedResult;
LOAD *, MapSubString('Mapcolor', ProductName) as TempField INLINE [
ProductName
GIA | SILVER DIAMANTE SPIKE DETAIL HOOP EARRINGS SILVER

AURORA | LIGHT MOCHA ONE SHOULDER CAPE SLEEVE JUMPSUIT LIGHT MOCHA
];

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

Hi Mayil, 

Thank you for your reply, but unfortunately this did not work as it removed some of the Product names, ex; WHITE BELTED FRONT TAILORED BLAZER WHITE, it changed it to WHITE BELTED FRONT TAILO , so it assumed that the Tailored the red as a colour

AmirMoha
Contributor III
Contributor III
Author

I have finally got this fixed,  with the below functions

LOAD *,
    Left(ProductName, Len(Trim(ProductName)) - Len(Trim(Colour))) as Product_name;