Skip to main content
Hello, everyone.

 

My customer asked for a chart showing his leads grouped by top 10 "POLO__c", a custom field.

 

The problem is, he wants to see all the others "POLO"s grouped as "others".

 

There is a way to do this?

 

Here is my query for this step.

 

q = load "MKT_Leads1";

 

q = group q by 'Polo__c';

 

q = foreach q generate 'Polo__c' as 'Polo__c', count() as 'count';

 

q = order q by 'Polo__c' desc;

 

q = limit q 10;

 

 
3 个回答
  1. 2018年4月3日 18:00
    Hello Andre,

     

    For calculating the sum of Others, you could use the offset parameter. Please try the following:

     

    q = load "MKT_Leads1";

     

    q = group q by 'Polo__c';

     

    q = foreach q generate 'Polo__c' as 'Polo__c', count() as 'count';

     

    q = order q by 'Polo__c' desc;

     

    q = limit q 10;

     

    r = load "MKT_Leads1";

     

    r = group r by 'Polo__c';

     

    r = foreach r generate 'Polo__c' as 'Polo__c', count() as 'count';

     

    r = order r by 'Polo__c' desc;

     

    r = offset r10;

     

    r = group r by all;

     

    r = foreach r generate "Others" as 'Polo__c', sum('count') as 'count';

     

    Depending on how you want to present the data, you could run the 2nd part of the query as a seperate step to come up with the Total for Others or even combine the two queries with a union grouping by 'Polo__c'.

     

    Hope this helps.

     

    Best Regards,

     

    Akshay