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: 
louise119
Creator III
Creator III

Script

Hi, how can I write a script to create a new table and take items from the currently loaded table and do the calculations?

I want to calculate the difference between dataA in table A and dataB in table B and create a new table with that item. How should I write the script?

1 Solution

Accepted Solutions
MayilVahanan

It will drop the intermediate table.

Here, FinalTable will be available in ur data model.

ex:

Temp:

Load DataA, Keyfield resident TableA;

Join

Load DataB, Keyfield resident TableB;

Finaltable:

Load Keyfield, DataA-DataB as DataC resident Temp;

Drop table Temp;

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.

View solution in original post

9 Replies
MayilVahanan

Hi

You need to join the 2 tables into one table with required fields with "Resident" load and do the calculation based on ur requirement.

ex:

Temp:

Load DataA, Keyfield resident TableA;

Join

Load DataB, Keyfield resident TableB;

Load Keyfield, DataA-DataB as DataC resident Temp;

Drop table Temp;

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
louise119
Creator III
Creator III
Author

Thank you so much.
Does "Drop table Temp;" mean that the table Temp is not created?

I want to create the new table with the value I calculated.

MayilVahanan

It will drop the intermediate table.

Here, FinalTable will be available in ur data model.

ex:

Temp:

Load DataA, Keyfield resident TableA;

Join

Load DataB, Keyfield resident TableB;

Finaltable:

Load Keyfield, DataA-DataB as DataC resident Temp;

Drop table Temp;

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
louise119
Creator III
Creator III
Author

Thank you so much!

What do you mean "Keyfield"?

MayilVahanan

hi

I think, you're trying to understand Qlik.

KeyField is common field between tables.

Data C is the new field after subtract Data A and Data B.

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
louise119
Creator III
Creator III
Author

If the shared fields of table A and table B are A.date and B.date respectively, will it be as follows?
what about the red part?

ex)
Temp:
Load DataA, A.date resident TableA;
Join
Load DataB, B.date resident TableB;

Finaltable:
Load Keyfield, DataA-DataB as DataC resident Temp;

Drop table Temp;

MayilVahanan

HI 

Can you mention the common fields between the tables and also share the data model to understand better

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
louise119
Creator III
Creator III
Author

I want to create the new table which has (Sales.Invoice Date - Item_master.Date).

data.png

data_1.png

MayilVahanan

Hi

Actually, you can see tables via data model viewer.. It will give clear picture.

I think, common fields between 2 tables is "itemNumber". If so, in ur case, Itemnumber is the key field.

And also, for your scenario, you can use Mapping and ApplyMap also. 

Like

MapTable:

Mapping Load ItemNumber, Date resident ItemMaster;

 

Load *, ApplyMap('MapTable', ItemNumber, 'NA') as ItemMasterDateValue from yoursalestable;

 

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.