Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
teruru
Contributor III
Contributor III

Calculation 2 columns of the same table

Hi

Id like to calculate ( columnA * columnB).
These are the same table.

How can I calculate with script?

4 Replies
JHuis
Creator III
Creator III

CAn you give an example of your data?

 

N30fyte
Creator
Creator

Here's one way, with a small amount of inline data:

 

multiples:
load * Inline
[columna, columnb
4,5
2,6
3,7
9,12
];


multiplier:
Load
columna,
columnb,
(columna*columnb) as columnc
Resident
multiples;
drop table multiples;

 

Screenshot 2023-10-20 103422.png

teruru
Contributor III
Contributor III
Author

Thank you 

When I have a data like the pic., I wanna calculate below.(keys are ID and data.)
I would like to get the ResultC.

cal1)sum(data 2) as ResultA
cal2)data2/ResultA as. ResultB
cal3)Result(data1*ResultB) as ResultC


Do you have any idea of script?
I wrote the script, but I can't get the value I expected.

key: ID&Date as Key


[Script]
Temp:
Load
key,
Sum(data2) as ResultA
Resident [File_Name]
Group By key;

Left Join(Temp)
Load
key,
data2/ResultA as ResultB
Resident Temp0
Group By key;

Left Join(Temp)
Load
key,
Sum(data1*ResultB) as ResultC
Resident Temp0
Group By key;

samp.png

teruru
Contributor III
Contributor III
Author

Thank you 

When I have a data like the pic., I wanna calculate below.(keys are ID and data.)
I would like to get the ResultC.

cal1)sum(data 2) as ResultA
cal2)data2/ResultA as. ResultB
cal3)Result(data1*ResultB) as ResultC


Do you have any idea of script?
I wrote the script, but I can't get the value I expected.

key: ID&Date as Key

[Script]

Temp:
Load
key,
Sum(data2) as ResultA
Resident [File_Name]
Group By key;

Left Join(Temp)
Load
key,
data2/ResultA as ResultB
Resident Temp0
Group By key;

Left Join(Temp)
Load
key,
Sum(data1*ResultB) as ResultC
Resident Temp0
Group By key;


samp.png