Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How can we create a new field based on the values of some other fields??

Can someone help me to resolve this issue?

I have four columns Say

Product 1_SalesProduct 2_SalesProduct 3_SalesProduct 4_Sales
1001000
045600
001230
000345

Now the challenge is to create a new column field called Type with a Text,which is based on the <>0 Value in the first 4 columns.

Product 1_SalesProduct 2_SalesProduct 3_SalesProduct 4_SalesType
1001000Good
045600Bad
001230Average
000345Better

Please share your solutions???

14 Replies
sunny_talwar

Ya this seems like a formatting issue then. If that is fixed, the above script will give you the results you are looking for. Can you fix the format in the database itself?

Best,

S

sunny_talwar

For handling the negative value issue, I would use the fabs function. Use the below script:

Table:

LOAD * INLINE [

    Product 1 Sales, Product 2 Sales, Product 3 Sales, Product 4 Sales

    -1001, 0, 0, 0

    0, 456, 0, 0

    0, 0, 123, 0

    0, 0, 0, 345

];

Table2:

LOAD *,

  If(Rangemax(fabs([Product 1 Sales]), fabs([Product 2 Sales]), fabs([Product 3 Sales]), fabs([Product 4 Sales])) = RangeMax(fabs([Product 1 Sales])), 'Good',

  If(Rangemax(fabs([Product 1 Sales]), fabs([Product 2 Sales]), fabs([Product 3 Sales]), fabs([Product 4 Sales])) = RangeMax(fabs([Product 2 Sales])), 'Bad',

  If(Rangemax(fabs([Product 1 Sales]), fabs([Product 2 Sales]), fabs([Product 3 Sales]), fabs([Product 4 Sales])) = RangeMax(fabs([Product 3 Sales])), 'Average',

  If(Rangemax(fabs([Product 1 Sales]), fabs([Product 2 Sales]), fabs([Product 3 Sales]), fabs([Product 4 Sales])) = RangeMax(fabs([Product 4 Sales])), 'Better')))) as Type

Resident Table;

DROP Table Table;

Best,

S

Not applicable
Author

looks like its giving me the desired results!!!!

Thanks a ton!!!!

sunny_talwar

Not a problem. Hope you have a good one.

Best,

S

timanshu
Creator III
Creator III

Can You Attach excel/qvw/screenshot of original data To give more clear picture of issue??