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: 
Not applicable

Calculate 2 fields in script

Hi community,

i load 2 tables in a script. E.g.

T1: contains field a

T2: contains filed b

now i want to subtract field a from field b as a new one. E.g. sum(a-b) as c.

Is this possible in my script?

1 Solution

Accepted Solutions
tresesco
MVP
MVP

Try something like this:

Table1:

Load part_no,

         Stock

From <your source>;

Join   // left/right/inner whicever is applicable

Load part_no,

          Safety

From <your source>;

NoConcatenate

Final:

Load *,

          (Stock-Safety) as Difference

Resident Table1;

Drop Table Table1;

View solution in original post

6 Replies
Gysbert_Wassenaar

That's only possible if you first combine the two tables into one table. You can use join for this.


talk is cheap, supply exceeds demand
yevgeniy
Creator
Creator

T1: contains field a

join(T1)

T2: contains filed b

and need

T3:

load

a,

b,

a+b as c

resident T1

Anonymous
Not applicable
Author

HI,

Do you want to calculate all combinations possible of sum(a-b)?

If so, you can do

JOIN(T1)

LOAD

b

RESIDENT

T2;

You'll now have your field a and b in the table T1 and you can do:

Concatenate

(T1)

LOAD

*,

sum(a-b)

RESIDENT

    T1;

Otherwise, you should have at least one field in common in table T1 and T2 which will let you join field a to b.

Can you explain little more your need? And even join your qvw will be better.

Not applicable
Author

Hi,

i have one field in common in both tables. Its 'part_no'. In table T1 is the stock in table T2 is the safety stock.

And now i need the difference between stock and safety stock.

Thanks for you support guys.

tresesco
MVP
MVP

Try something like this:

Table1:

Load part_no,

         Stock

From <your source>;

Join   // left/right/inner whicever is applicable

Load part_no,

          Safety

From <your source>;

NoConcatenate

Final:

Load *,

          (Stock-Safety) as Difference

Resident Table1;

Drop Table Table1;

rajeshvaswani77
Specialist III
Specialist III

Hi,

Use applymap and bring the field you need from 2nd table to 1st table. Then do preceding load in 1st table and calculate the sum. That's the way I have done in many instances and it works fine.

thanks,

Rajesh Vaswani