Use Script To Count Records

This recipe demonstrates on counting records using script.

  1. Derivation_Count_cmp.ds:Count all the records in the data.
    Example:
    A - 1
    A - 2
    B - 3
    B - 4
    B - 5
    C - 6
    C - 7Steps taken:
  2. Create a composite datasource (Derivation_Count_cmp.ds). Drag and drop FruitSales.ds as the beginning of the flow.
  3. Add a “Derivative” element following FruitSales.ds. Add the following columns into “Derivative > Derived” tab:(Column1) Name=MCount Type=Integer Value=count++;
    (Column2) Name=MTotal Type=Integer Value=Mtotal();
  4. Enter the following script into “Derivative > JavaScript” tab:function Mtotal(){
    return total;
    }
  5. Script_HashMap_Count_cmp.ds:Count the records based on field name.
    Example:
    A - 1
    A - 2
    B - 1
    B - 2
    B - 3
    C - 1
    C - 2Steps taken:
  6. Create a composite datasource (Script_HashMap_Count_cmp.ds). Drag and drop FruitSales.ds as the beginning of the flow.
  7. Add a “Sort” element following FruitSales.ds. Add the following sort details:Column Name=Fruit Sort Order= Ascending Group On=None
  8. Add a “Derivative” element following the “Sort” element. Add the following column into “Derivative > Derived”:Column Name=MCount Type=Integer Value=add(Fruit)To download the necessary files for this recipe, refer to the attached ZIP file.
    ScriptToCountRecord.zip