Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
ZuzJsk007
Contributor III
Contributor III

calculated field in script load

Hi everybody!

I'm new to Qlik and  I stumbled upon a problem in script load. I need to calculate a field (let's call it "NewField") in Table 1 based on specific values from a field in Table 2 (let's call it "Source"). Tables are linked via "ID" field. The logic of the calcualtion should be like this:

IF ID = 1 

 THEN  sum of values in field Source for ID = 2  and 3 and 4

 ELSE sum of values in field Source

(syntax is completely made-up just to illustrate the calcualtion that the ID=1 has a special formula behind)

 

Let's have an example:

 

Table2:

ID    Value

1         1

2         2

3         3

4         4

 

Table1:

ID   NewField

1         2+3+4=9

2         2

3         3

4         4

 

Do you have any ideas, please?

Labels (2)
1 Solution

Accepted Solutions
sunny_talwar

Something like this

Table2:
LOAD * INLINE [
    ID, Value
    1, 1
    2, 2
    3, 3
    4, 4
];

Left Join (Table2)
LOAD 1 as ID,
	 Sum(Value) as NewValue
Resident Table2
Where Match(ID, 2, 3, 4);

Table1:
LOAD ID,
	 Alt(NewValue, Value) as NewField
Resident Table2;

DROP Table Table2;

View solution in original post

2 Replies
sunny_talwar

Something like this

Table2:
LOAD * INLINE [
    ID, Value
    1, 1
    2, 2
    3, 3
    4, 4
];

Left Join (Table2)
LOAD 1 as ID,
	 Sum(Value) as NewValue
Resident Table2
Where Match(ID, 2, 3, 4);

Table1:
LOAD ID,
	 Alt(NewValue, Value) as NewField
Resident Table2;

DROP Table Table2;
ZuzJsk007
Contributor III
Contributor III
Author

This is brilliant!! Thank you very much! 🙂