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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
safik003
Contributor III
Contributor III

Replace values with one value for unique ID

Hi,

I have a table with ID and Value field. I want to replace all values with a single value for a condition.

For example if a ID contains "Apple" Replace all values with "Fruit" for a thatID, if it doesn't contain "Apple" replace with others.

Below is my table

Test:
Load * INLINE [
ID, Value
1, Apple
1, Orange
1, Banana
2, Apple
2, Mango
2, Date
3, Wallnut
4, Peas
5, Papaya
5, Apple
5, Orange
];

 

My output expectation is below.

 

Test2:

ID, Value
1, Fruit
2, Fruit
3, Others
4, Others
5, Fruit

 

Suggestion please. Sample file attached.

2 Solutions

Accepted Solutions
Taoufiq_Zarra

attached

Capture.PNG

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉

View solution in original post

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Try this code.

Test:
Load * INLINE [
ID, Value
1, Apple
1, Orange
1, Banana
2, Apple
2, Mango
2, Date
3, Wallnut
4, Peas
5, Papaya
5, Apple
5, Orange
];

FindIDwithApple:
Load Distinct ID as AppleID
Resident Test where Value = 'Apple';

Final:
Load Distinct ID as ID1,If(Exists(AppleID,ID),'Fruit','Other') as Value1
Resident Test;

 

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!

View solution in original post

2 Replies
Taoufiq_Zarra

attached

Capture.PNG

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Try this code.

Test:
Load * INLINE [
ID, Value
1, Apple
1, Orange
1, Banana
2, Apple
2, Mango
2, Date
3, Wallnut
4, Peas
5, Papaya
5, Apple
5, Orange
];

FindIDwithApple:
Load Distinct ID as AppleID
Resident Test where Value = 'Apple';

Final:
Load Distinct ID as ID1,If(Exists(AppleID,ID),'Fruit','Other') as Value1
Resident Test;

 

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!