This recipe demonstrates on counting records using script.
- 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: - Create a composite datasource (Derivation_Count_cmp.ds). Drag and drop FruitSales.ds as the beginning of the flow.
- 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(); - Enter the following script into “Derivative > JavaScript” tab:function Mtotal(){
return total;
} - 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: - Create a composite datasource (Script_HashMap_Count_cmp.ds). Drag and drop FruitSales.ds as the beginning of the flow.
- Add a “Sort” element following FruitSales.ds. Add the following sort details:Column Name=Fruit Sort Order= Ascending Group On=None
- 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