Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
@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;
@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;
Try this
table:
Load BRANCH,
Sum(if (Segment='Engaged', CUST_CNT,0))/Sum(CUST_CNT) as CalculatedField
Resident tab
Group By BRANCH, Segment;
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
Thank you very much @qv_testing for your help.