Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi Coders,
I'm new to Qlik Sense and trying to figure out how to create calculated fields while data is being loaded in load editor. I have excel file with below fields & calculation is defined below.
Score Level: =IFS(B2="L", 1, B2 = "M", 2, B2="H", 3) - This I have got in load editor, No action needed here.
I need below fields to be calculated in load editor.
Count: =COUNTIF(A:A,A2)
Max: =MAX(D:D)
Min: =MIN(D:D)
Vol: =D2/($E$2-$F$2)+1
Avg: =SUMIF(A:A,A2,C:C)/COUNTIF(A:A,A2)
Score: =H2*G2
Avg of Score - Can we get the Average of Score field mentioned above. I need to achieve below pivot after all fields are calculated and loaded.
Is this doable in Qlik Sense Load editor ? if Yes, can you guys please help me out in achieving this output.
I've included excel file also for your reference. any help will be really appreciated.
Thanks in advance,
Rowdy
@RowdyBoy9 Please see below that I have created in the load script editor.
NoConcatenate
Temp:
LOAD
Controls,
Level,
"Score Level",
"Count",
"Max",
"Min",
Vol,
"Avg",
Score
FROM [lib://Qlik Community Practice/Control.xlsx]
(ooxml, embedded labels, table is Sheet1);
Max:
Load
Max(Count) as Max_Count
Resident Temp;
Min:
Load
Min(Count) as Min_Count
Resident Temp;
Vmax=Peek('Max_Count',0,'Max');
Vmin=Peek('Min_Count',0,'Min');
NoConcatenate
Temp1:
Load Controls,
Count(Controls) as [Count_of_Controls]
Resident Temp
group by Controls;
left join (Temp1)
Temp2:
Load Controls,
Avg(Vol*Avg) as [Avg of Scores]
Resident Temp
group by Controls;
left join (Temp1)
Temp3:
Load Controls,
(Sum(Count)/count(Controls)) as [Average of Avg]
Resident Temp
group by Controls;
left join (Temp1)
Temp4:
Load Controls,
Avg((Count)/('$(Vmax)'-'$(Vmin)')+1) as [Average of Vol]
Resident Temp
group by Controls;
Drop table Temp,Max,Min;
Exit Script;
@RowdyBoy9 if this resolves your issue, please like and accept it as a solution.
Hi @sidhiq91 Thank you for your quick response, I really appreciate it. I see there is no Count calculated in the script. I'm getting below error.
@RowdyBoy9 here we go! This should sort out your issue. If this resolves issue please like and accept it as a solution.
NoConcatenate
Temp:
LOAD
Controls,
Level,
"Score Level",
//"Count",
"Max",
"Min",
Vol,
"Avg",
Score
FROM [lib://Qlik Community Practice/Control.xlsx]
(ooxml, embedded labels, table is Sheet1);
left join (Temp)
Load Controls,
Count(Controls) as Count
Resident Temp
group by Controls;
Max:
Load
Max(Count) as Max_Count
Resident Temp;
Min:
Load
Min(Count) as Min_Count
Resident Temp;
Vmax=Peek('Max_Count',0,'Max');
Vmin=Peek('Min_Count',0,'Min');
NoConcatenate
Temp1:
Load Controls,
Count(Controls) as [Count_of_Controls]
Resident Temp
group by Controls;
left join (Temp1)
Temp2:
Load Controls,
Avg(Vol*Avg) as [Avg of Scores]
Resident Temp
group by Controls;
left join (Temp1)
Temp3:
Load Controls,
(Sum(Count)/count(Controls)) as [Average of Avg]
Resident Temp
group by Controls;
left join (Temp1)
Temp4:
Load Controls,
Avg((Count)/('$(Vmax)'-'$(Vmin)')+1) as [Average of Vol]
Resident Temp
group by Controls;
Drop table Temp,Max,Min;
Exit Script;
Hi @sidhiq91, I'm getting error as
As I mentioned earlier to this post, I need to calculate formulas for all the fields not just Count. I need calculation for Vol, Avg & Score as well.
The above code resolved the calculation for Count, Max & Min fields. I need calculation for vol, avg & score as well.
would you please help me out.
Thanks in advance.
@RowdyBoy9 Apologies for the delayed response, was sick. Please find below script for all the variables and this should sort out your issue.
NoConcatenate
Temp:
LOAD
Controls,
Level,
"Score Level"
//"Count",
// "Max",
//"Min",
//Vol,
// "Avg",
//Score
FROM [lib://Qlik Community Practice/Control.xlsx]
(ooxml, embedded labels, table is Sheet1);
left join (Temp)
Load Controls,
Count(Controls) as Count
Resident Temp
group by Controls;
Max:
Load
Max(Count) as Max_Count
Resident Temp;
Min:
Load
Min(Count) as Min_Count
Resident Temp;
Vmax=Peek('Max_Count',0,'Max');
Vmin=Peek('Min_Count',0,'Min');
Left join (Temp)
Load Controls,
Avg([Score Level]) as Avg
Resident Temp
group by Controls;
Left Join (Temp)
Load Controls,
(Sum(Count)/Sum(('$(Vmax)'-'$(Vmin)')))+1 as Vol
Resident Temp
group by Controls;
Left Join (Temp)
Load Controls,
Level,
sum(Vol*Avg) as Score
Resident Temp
group by Controls,Level;
NoConcatenate
Temp1:
Load Controls,
Count(Controls) as [Count_of_Controls]
Resident Temp
group by Controls;
left join (Temp1)
Temp2:
Load Controls,
Avg(Vol*Avg) as [Avg of Scores]
Resident Temp
group by Controls;
left join (Temp1)
Temp3:
Load Controls,
Avg(Avg) as [Average of Avg]
Resident Temp
group by Controls;
left join (Temp1)
Temp4:
Load Controls,
Avg((Count)/('$(Vmax)'-'$(Vmin)')+1) as [Average of Vol]
Resident Temp
group by Controls;
Drop table Temp,Max,Min;
Exit Script;
Hi @sidhiq91 , No worries. I have figured it out in creating the calculated fields in the load editor script and thank you for your solution as well.
Cheers!!