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: 
Ahmed_Turnaround

Calculation within Script

Hi,

 

I did some research and couldn't find the answer, so I thought I'd make a new topic and hope that hasn't broken any rules. I am trying to put a calculated field within my Load Script but I'm having trouble doing this. My script, currently is as follows:

 

GLBALANCEMASTER:
LOAD [GL BAL KEY],
[BALANCE FILE SUMMARY LEVEL],
[GL COMPANY ID],
[PROFIT CENTRE ID],
[GL ACCOUNT MAJOR ID],
[GL ACCOUNT MINOR ID],
[GL CURRENCY],
[YEAR END],
[OPENING BALANCE FOR YEAR],
[GL PERIOD NN],
[GL MOVEMENT BASE],
[GL PERIOD],
[CLOSING BALANCE BASE],
[GL MOVEMENT CONSOL1],
[GL MOVEMENT CONSOL2],
[CLOSING BALANCE CONSOL1],
[CLOSING BALANCE CONSOL2],
[GL ACCOUNT MINOR],
[GL BAL KEY] & '%' & [GL PERIOD NN] as [GL_BAL_KEY_2]
FROM
[E:\Qlikdata\IP1 Insight Pack 1.4\Data\TA.GLBalance.qvd]
(QVD);

MAPCG:
LOAD [GL ACCOUNT MAJOR ID],
[PROFIT CENTRE ID],
[Sub Category ID] as [SUB CATEGORY ID],
[Sub Category Sale or Cost ID] as [SUB CATEGORY SALE OR COST ID]
FROM
[E:\Qlikdata\IP1 Insight Pack 1.4\Data\TA.MAPCG.qvd]
(qvd);

SUBCATEGORY:
LOAD [Sub Category ID] as [SUB CATEGORY ID],
[Sub Category Description] as [SUB CATEGORY DESCRIPTION],
[Sub Category Sale or Cost ID] as [SUB CATEGORY SALE OR COST ID]
FROM
[E:\Qlikdata\IP1 Insight Pack 1.4\Data\TA.AccountSubCategory.qvd]
(qvd);

SALECOST:
LOAD [Sub Category Sale or Cost ID] as [SUB CATEGORY SALE OR COST ID],
[Sub Category Sale or Cost Description] as [SUB CATEGORY SALE OR COST DESCRIPTION]
FROM
[E:\Qlikdata\IP1 Insight Pack 1.4\Data\TA.AccountSaleCost.qvd]
(qvd);

JOIN (GLBALANCEMASTER)
LOAD * RESIDENT MAPCG;

JOIN (GLBALANCEMASTER)
LOAD * RESIDENT SUBCATEGORY;

JOIN (GLBALANCEMASTER)
LOAD * RESIDENT SALECOST;

DROP TABLE MAPCG;
DROP TABLE SUBCATEGORY;
DROP TABLE SALECOST;

 

I then want to calculate a figure based on whether a sub category ID matches a specific number. I have the following code, which I've put before the DROP TABLES command, but it doesn't seem to work:

 

CALCULATIONS:
LOAD
[SUB CATEGORY ID],
(SUM({<[SUB CATEGORY ID] = {'10'}>} [GL MOVEMENT BASE]) *-1) as [TEST TOTAL TRADE SALES]
RESIDENT (GLBALANCEMASTER)
GROUP BY [SUB CATEGORY ID];

 

Below is what is underlined in error:

Screenshot 1.PNG

 

Any ideas what I am doing wrong?

3 Replies
Brett_Bleess
Former Employee
Former Employee

Only thing of which I can think may be quote related, here is a Design Blog link to check on things there:

https://community.qlik.com/t5/Qlik-Design-Blog/Quotes-in-Set-Analysis/ba-p/1471824

If you need to do some further searching, you can use the following URL to have access to the search box:

https://community.qlik.com/t5/Qlik-Design-Blog/bg-p/qlik-design-blog

My post will kick things back up again too, so someone else may revisit and confirm or point out something else.

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.
sunny_talwar

Set analysis is a concept used on the front end of an application. Backend can use if statement like this

CALCULATIONS:
LOAD [SUB CATEGORY ID],
      -1* SUM(If([SUB CATEGORY ID] = 10, [GL MOVEMENT BASE])) as [TEST TOTAL TRADE SALES]
Resident GLBALANCEMASTER
Group By [SUB CATEGORY ID];

or you can do this

CALCULATIONS:
LOAD [SUB CATEGORY ID],
      -1 * SUM([GL MOVEMENT BASE]) as [TEST TOTAL TRADE SALES]
Resident GLBALANCEMASTER
Where [SUB CATEGORY ID] = 10
Group By [SUB CATEGORY ID];
Ahmed_Turnaround
Author

Thanks guys, will review and get back to you all ASAP.