Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi Guys
i have an sql script and my percentage is working perfectly fine but when i transfer this to qlik sense its not working - how can i calculate percentage in load script ?
my sample is below:
select 1,2,3 from cte1
union all
select 1,2,3 from cte2
union all
select 1,2, %of sum of cte1 and sum of cte2 -- this is where am struggling - want this in load script as i want it display as a row not column
Can you provide sample data set for cte1 and cte2 and well as example of what resulting table should look like after calculating %of sum of cte1 and sum of cte2 as a row
select datemonth
,Code = '1'
,ProductCode
,count(distinct Productcode) TotalProducts
from Sales
where statuss = 'active'
union ALL
select datemonth
,Code = '2'
,ProductCode
,count(distinct Productcode) TotalDamaged
from Sales
where statuss = 'damaged'
Union All
select datemonth
,Code = '3' ---% of product damaged
,productcode
,ROUND(CAST(COUNT(distinct TotalDamaged) * 100.0 / COUNT(TotalProducts)AS FLOAT), 2) ----
from Sales
where statuss in ('damaged','active')
-- This works ok in sql and not in Qlik sense
-- i do not want to create the percentage as an expression want it in the load script
Hi ,
From your example ,
you can try something like this ,
Table1:
select datemonth
//,Code = '1'
,ProductCode
,count(distinct Productcode) TotalProducts,Datemonth+ProductCode as Key
from Sales
where statuss = 'active'
Left join ( Table1)
Load *;
select datemonth
//,Code = '2'
,ProductCode
,count(distinct Productcode) TotalDamaged,Datemonth+ProductCode as Key
from Sales
where statuss = 'damaged'
Left join ( Table1)
Load *, Total Damaged/Total products as %
Resident Table1;