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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Adding two fields in the script

Good afternoon,

I´ve got two tables with the same structure, one containing "primary" and the other containing "secondary" costs. The structure is like

PrimaryCost:

Year

Company

CostCenter

Account

ValueInJan

ValueInFeb

....

ValueInDec

I´d like to split this by month adding the values from both tables. I load with a qualify on the values, then I join SecondaryCost into PrimaryCost for easier handling. So far, so good.

Then I set up a final table cost as follows, repeating per month. However, the addition doesn´t work and my field Value is initial - why?

Cost:

load
Y
ear

Company

CostCenter

Account

PrimaryCost.ValueInJan + SecondaryCost.ValueInJan as Value,

'001' as Month
resident PrimaryCost;

18 Replies
Not applicable
Author

It loads but shows a '-' as value in the table viewer.

sunny_talwar

What about when you just do

SecondaryCost.ValueInJan as Value

'001' as Month



Does it still work?

Not applicable
Author

Yes, each field individually works!

sunny_talwar

May be the values are text strings and not numeric values. Can you try changing them to Numeric value using Num#() function. I am using '#', but if the value has commas and two decimals then '#,###.00'.

FinalTable:

LOAD *,

          Num#(PrimaryCost.ValueInJan, '#') + Num#(SecondaryCost.ValueInJan, '#') as Value,

          '001' as Month

Resident PrimaryCost;


See if this helps

Not applicable
Author

Thanks Sunny. I already did that, the fields are numeric and are treated as such in tables etc.

sunny_talwar

I guess Gabsus04 is right then. We would need to see a sample to actually see what is going wrong, because I don't think there is anything wrong with the syntax.

Not applicable
Author

OK, you guys are right. Due to the join, I see with the table viewer on table PrimaryCost records with say value 123 for PrimaryCost.ValueInJan and - for SecondaryCost.ValueInJan. How can I nevertheless add the two? Would you recommend other joins or no joins and if yes, how do you achieve the aforementioned goal?

Gabriel
Partner - Specialist III
Partner - Specialist III

Hi,

What I would recommend doing is to use APPLYMAP.


Not applicable
Author

OK, thanks. The solution was even simpler: I dropped the qualify story, just loaded the primary and the secondary costs directly into one table (that keeps the individual records from the two sources I guess), and then did a load resident like this

load
Y
ear

Company

CostCenter

Account

ValueInJan as Value,

'001' as Month