Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Load Script If Help

I keep getting Invalid Expression with the following load script:

Insource%:

Load

AcctDesc,

Cost,

If(AcctDesc='Demand Service' or AcctDesc='Demand Parts',Sum(Cost),0)/Sum(Cost) as Insource

Resident MasterCostTable;

1 Solution

Accepted Solutions
maxgro
MVP
MVP

- add a group by

- I don't understand the if, it seems sum(Cost) / sum(Cost)    or   0 / sum(Cost), so  1  or 0

Insource%:

Load

AcctDesc,

Cost,

//If(AcctDesc='Demand Service' or AcctDesc='Demand Parts',Sum(Cost),0)/Sum(Cost) as Insource

If(AcctDesc='Demand Service' or AcctDesc='Demand Parts',Sum(Cost),0) as Insource

Resident MasterCostTable

group by AcctDesc, Cost;

View solution in original post

4 Replies
maxgro
MVP
MVP

- add a group by

- I don't understand the if, it seems sum(Cost) / sum(Cost)    or   0 / sum(Cost), so  1  or 0

Insource%:

Load

AcctDesc,

Cost,

//If(AcctDesc='Demand Service' or AcctDesc='Demand Parts',Sum(Cost),0)/Sum(Cost) as Insource

If(AcctDesc='Demand Service' or AcctDesc='Demand Parts',Sum(Cost),0) as Insource

Resident MasterCostTable

group by AcctDesc, Cost;

Not applicable
Author

The If statement is declaring a subset of costs to divide by the total cost.

datagrrl
Creator III
Creator III

What Maxgro said.

Maybe this if you actually want your costs summed up in the script:

Insource%:

Load

AcctDesc,

sum(Cost)as Cost,

sum(If(AcctDesc='Demand Service' or AcctDesc='Demand Parts',Cost,0))/Sum(Cost) as Insource

Resident MasterCostTable

group by AcctDesc;

datagrrl
Creator III
Creator III

I am wondering if you wouldn't want to do this in a chart. Then you could use the Total keyword in your expression.