Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
teruru
Contributor III
Contributor III

Calculate data with script

Hi, I have a problem of calculating with script.

When I have a data like the pic., I wanna calculate below.(keys are ID and data.)
Does anyone know how to make the script?
I would like to get the ResultC.

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


samp.png


Thank you.

3 Replies
Mark_Little
Luminary
Luminary

SUM(data1*ResultB) AS ResultD

You can't Reference ResultC as does not exist until the table is loaded.

teruru
Contributor III
Contributor III
Author

thank you,

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 ResultD
Resident Temp0
Group By key;

I would like to get the value of ResultD.(depends on key)

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