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: 
Eshwar1
Contributor III
Contributor III

Script expression(derived field)

Hi All,

I have created below expression in front end in Table Chart.

in Table Dimension: Branch and Expression is like below

Sum({<Segment={'Engaged'}>}CUST_CNT)/Sum(Total <BRANCH>CUST_CNT)

it is giving percentage value as expected.

same expression i want to write in script side (to have derived field)

Can you suggest on this.

Thanks in Advance

-Eshwar

Labels (2)
1 Solution

Accepted Solutions
pravinboniface
Creator III
Creator III

@Eshwar1 Please see if this works for you.  I tried with the sample data and the front end values matches the script values.

// Sample data
tab:
Load * inline [
BRANCH,Segment,CUST_CNT
1,'Engaged',5
1,'Disengaged',20
2,'Engaged',15
2,'Disengaged',200
];

// Script matching frontend expression
// Sum({<Segment={'Engaged'}>}CUST_CNT)/Sum(Total <BRANCH>CUST_CNT)

derived_table:
NoConcatenate
Load BRANCH, Sum(if (Segment='Engaged', CUST_CNT,0))/Sum(CUST_CNT) as Engaged_Rate
Resident tab
Group By BRANCH;

drop table tab;
Exit script;

 

View solution in original post

4 Replies
pravinboniface
Creator III
Creator III

@Eshwar1 Please see if this works for you.  I tried with the sample data and the front end values matches the script values.

// Sample data
tab:
Load * inline [
BRANCH,Segment,CUST_CNT
1,'Engaged',5
1,'Disengaged',20
2,'Engaged',15
2,'Disengaged',200
];

// Script matching frontend expression
// Sum({<Segment={'Engaged'}>}CUST_CNT)/Sum(Total <BRANCH>CUST_CNT)

derived_table:
NoConcatenate
Load BRANCH, Sum(if (Segment='Engaged', CUST_CNT,0))/Sum(CUST_CNT) as Engaged_Rate
Resident tab
Group By BRANCH;

drop table tab;
Exit script;

 

qv_testing
Specialist II
Specialist II

Try this

table:
Load BRANCH,
         Sum(if (Segment='Engaged', CUST_CNT,0))/Sum(CUST_CNT) as CalculatedField
Resident tab
Group By BRANCH, Segment;

Eshwar1
Contributor III
Contributor III
Author

Thank you very much Pravinboniface, it is working as expected.

just added Number format.


Num(Sum(if(CLCM_Segment='04. Fully Engaged', CUST_CNT,0))/Sum(CUST_CNT),'#,##0.00%') as Engaged_rate

Eshwar1
Contributor III
Contributor III
Author

Thank you very much @qv_testing for your help.