Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Our next Qlik Insider session will cover new key capabilities. Join us August 11th REGISTER TODAY
cancel
Showing results for 
Search instead for 
Did you mean: 
RogerG
Contributor III
Contributor III

Summing cost by product and merging it with existing data

so I have a table of products that consist of supply cost, development cost and internal cost

Internal cost is calculated based on supply cost - development costs

I am trying to do all this in the load script in order to keep the interface charts clean.  I am afraid that may not be possible

 

My data set looks like this

Products:

Load * inline [

Product, account, year, cost

Product1, Supply, 2020, 1000

Product1, Development,2020 2000

Product1, internals, 2020, // need to calculate this value

Product1, Supply, 2021, 3000

Product1, Development, 2021, 5000

Product1, Internal, 2021, // need to calculate this value

]

so the calculation would be development - supply = 1000

1 Reply
PriyankaShivhare
Creator II
Creator II

May be not the best solution but can be done like below

test:

load * ,
Product&'-'&year as %Key

Inline [


Product, account, year, cost

Product1, Supply, 2020, 1000

Product1, Development,2020, 2000

Product1, internals, 2020,

Product1, Supply, 2021, 3000

Product1, Development, 2021, 5000

Product1, internals, 2021,

];

 

temp:
Load  %Key,
sum(cost) as DevelopmentCost
Resident test
where account='Development'
group by %Key ;

left join(temp)

Load %Key,
sum(cost) as SupplyCost
Resident test
where account='Supply'
group by %Key ;

MapInternalCost:
Mapping Load
%Key,
DevelopmentCost-SupplyCost as InternalCost
Resident temp;

drop table temp;

NoConcatenate
Test1:
Load *,
if(account='internals',Applymap('MapInternalCost',%Key,null()),cost) as NewCost
Resident test;

drop table test;