Grouping data by field
This topic provides examples of how to use the group_function attribute within a field tag to group data. These grouping methods are supported for fields: sum, first, and last. The default method is first.
Example 1: Print sum of WRKD_MINUTES for each employee
In this example, the sum of WRKD_MINUTES is printed for each employee.
This is the full XML definition:
<payroll_export plugin="com.workbrain.app.export.payroll.basic.BasicPayrollExportPlugin"> 
  <data>
    <field name='emp_name' group='true'/>
    <field name='wrkd_minutes' group_function='sum'/>
    <field name='tcode_name'/>
    <field name='htype_name'/>
    <field name='wrks_authorized'/>
    <field name='retro'/>
    <dummy_field name='earn_code'/>
  </data>
  <logic>
    <match_output>
      <match field="wrks_authorized" value="Y" />
      <match field="tcode_name" value="%" />
      <match field="htype_name" value="REG" />
      <output_row>
        <map field="earn_code" value="1"  />
      </output_row >
    </match_output>
    <match_output>
      <match field="wrks_authorized" value="Y" />
      <match field="tcode_name" value="%" />
      <match field="htype_name" value="OT1.0" />
      <output_row>
        <map field="earn_code" value="4"  />
      </output_row>
    </match_output>
	
    <match_output>
      <match field="wrks_authorized" value="Y" />
      <match field="tcode_name" value="%" />
      <match field="htype_name" value="OT1.5" />
      <output_row>
        <map field="earn_code" value="2"  />
      </output_row>
    </match_output>
    <match_output>
      <match field="wrks_authorized" value="Y" />
      <match field="tcode_name" value="%" />
      <match field="htype_name" value="OT2.0" />
      <output_row>
        <map field="earn_code" value="5"  />
      </output_row >
    </match_output>
    <match_output>
      <match field="tcode_name" value="UAT" />
      <match field="htype_name" value="UNPAID" />
    </match_output>
    <match_output>
      <output_row>
        <map field="earn_code" value="E" />
      </output_row>
    </match_output>
  </logic>
  <format>
    <header>  
    </header>
        
    <body>
      <string field='emp_name' />
      <constant>,</constant>
      <string field='earn_code'/>
      <constant>,</constant>
      <number field='wrkd_minutes' format='########0.00' divide='60' null='***'/>
      <constant>,</constant>
      <string field='retro' />
      <new_line/>
    </body>
        
    <footer>         
    </footer>
  </format>
</payroll_export>This table shows a sample of the Payroll Export file output:
| emp_name | earn_code | wrkd_minutes | retro | 
|---|---|---|---|
| 2102 | 1 | 40.00 | N | 
| 2104 | 1 | 40.00 | N | 
| 3125 | 1 | 56.00 | N | 
Example 2: Print last value of WRKD_MINUTES for each employee
In this example, the last value of WRKD_MINUTES is printed for each employee.
The same XML definition is used as in Example 1, except the grouping method is last:
<field name='wrkd_minutes' group_function='last'/>This table shows a sample of the Payroll Export file output:
| emp_name | earn_code | wrkd_minutes | retro | 
|---|---|---|---|
| 5210 | 1 | 2.00 | Y | 
| 5211 | 1 | 10.00 | Y |