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: 
sifatnabil
Specialist
Specialist

subfield() creates extra rows

Hi,

Using subfield in script creates duplicate rows with the other delimited values, and when using sum(Amount) in a textbox, the summation is incorrect. How can this be rectified? e.g. if the original number of rows in script is 3, using subfield will double the number of rows to 6 if there are 2 subfields (like Product1, Product2). So sum(Amount) is doubled. Thanks.

1 Solution

Accepted Solutions
sunny_talwar

Two options:

1) May be use a aggregate function in the text box object to address this issue:

Script:

Table:

LOAD Dim,

  SubField(Product, '|') as Product,

  Value

Inline [

Dim, Product, Value

A, Product 1|Product 2, 50

B, Product 1|Product 3, 90

C, Product 2|Product 3, 120

];

Output in Table Box object:

Capture.PNG

Expression in Text Box object: =Sum(Aggr(Avg(Value), Dim))

2) Use a Separate table for SubField

Script:

Table:

LOAD *

Inline [

Dim, Product, Value

A, Product 1|Product 2, 50

B, Product 1|Product 3, 90

C, Product 2|Product 3, 120

];

Table2:

LOAD Dim,

  SubField(Product, '|') as Product1

Resident Table;

Expression in Text Box Object: =Sum(Value)

View solution in original post

6 Replies
Anonymous
Not applicable

Can you post the sample of your data for better understanding.

As subfield do not duplicates the data

sifatnabil
Specialist
Specialist
Author

Hi Nitin,

The original data is like this:

Amount, Products,

10, A, B

10, A, B

10, A, B

After using subfield():

Amount, Products,

10, A,

10, B

10, A,

10, B,

10, A,

10, B

Causing sum(Amount) to be incorrect.

sunny_talwar

Two options:

1) May be use a aggregate function in the text box object to address this issue:

Script:

Table:

LOAD Dim,

  SubField(Product, '|') as Product,

  Value

Inline [

Dim, Product, Value

A, Product 1|Product 2, 50

B, Product 1|Product 3, 90

C, Product 2|Product 3, 120

];

Output in Table Box object:

Capture.PNG

Expression in Text Box object: =Sum(Aggr(Avg(Value), Dim))

2) Use a Separate table for SubField

Script:

Table:

LOAD *

Inline [

Dim, Product, Value

A, Product 1|Product 2, 50

B, Product 1|Product 3, 90

C, Product 2|Product 3, 120

];

Table2:

LOAD Dim,

  SubField(Product, '|') as Product1

Resident Table;

Expression in Text Box Object: =Sum(Value)

sasiparupudi1
Master III
Master III

Use a preceeding load with distinct to eliminate the duplicates after your load with the subfield

Hth

Sasi

sifatnabil
Specialist
Specialist
Author

Thanks sunindia, the 2nd option works well. It preserves the original row count.

sunny_talwar

Ya it does and the expression is also simpler

I am glad I was able to help.

Best,

Sunny