# Data Mapping cfxdm - dm:groupby

**dm: groupby:** This cfxdm function allows the user to group the data (by rows) based on selected columns using aggregate functions.

**dm: groupby** synta&#x78;**:**&#x20;

* **columns** (mandatory)**:** Select one or more columns for grouping the data.
* **agg** (optional)**:**
  * **count:** It is applied by default when 'agg' is not specified. Supported on any value types (numeric or non-numeric values)
  * **min:** Supported on numeric values only
  * **max:** Supported on numeric values only
  * **sum:** Supported on numeric values only

### Example 1:

Step 1: Create an empty **dm\_groupby\_example\_1** using AIOps studio as shown in the below screenshot.

![Empty pipeline](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-Mfj-nEvHkrkl0_ED95q%2F-Mfj0H2yKC2fV9LJGHd5%2FScreen%20Shot%202021-07-28%20at%202.28.41%20PM.png?alt=media\&token=ac9f976e-7eb7-4d24-a3b7-1e58a8511312)

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment.\
\
\&#xNAN;*`##### This pipeline creates a set of records/dateset details coming from a vCenter`* \
*`##### environment. This dataset includes datastore details, Folder name, guest_hostname,`* \
*`##### guest_ip_address.`*\
\
*`######  This pipeline uses dm groupby to view the data grouped by selective column name`*\
*`######  Example by Folder, datastore etc.`*\
\
*`@dm:empty`* \
*``--> @dm:addrow datastore.1 = 'CFX-QA-Store-NFS-qnap' & Folder = '' & guest_full_name = 'CentOS 4/5/6/7 (64 bit)' & guest_hostname = 'test2.oia.cloudfabrix.com' & guest_ip_address = '10.95.134.17' & `VM Name` = 'test1'``*\
\
*``--> @dm:addrow datastore.1 = 'CFX-QA-Store-NFS-qnap' & Folder = 'User VMs' & guest_full_name = 'CentOS 4/5/6/7 (64 bit)' & guest_hostname = 'qa.oia.cloudfabrix.com' & guest_ip_address = '10.95.122.13' & `VM Name` = 'test2'``*\
\
*``--> @dm:addrow datastore.1 = 'ENG_ISOs,netapp-qa-nfs' & Folder = 'User VMs,Ravi-Pisupati,TestVMs' & guest_full_name = 'Ubuntu Linux (64 bit)' & guest_hostname = 'ubuntuqa' & guest_ip_address = '10.95.102.172' & `VM Name` = 'test3'``*\
\
*``--> @dm:addrow datastore.1 = 'datastore1 (6)' & Folder = 'Ravi-Pisupati' & guest_full_name = 'CentOS 4/5/6/7 (64 bit)' & guest_hostname = 'elkstack' & guest_ip_address = '10.95.121.218' & `VM Name` = 'test4'``*\
\
*`--> @dm:addrow datastore.1 = 'datastore1-198' & Folder = '' & guest_full_name = 'Microsoft Windows Server' & guest_hostname = 'spdnode.adwinstack' & guest_ip_address = '10.95.132.4'`* \
&#x20;*``& `VM Name` = 'test5'``*\
\
*``--> @dm:addrow datastore.1 = 'netapp-dev-nfs-01' & Folder = 'User VMs,Ravi-Pisupati,TestVMs' & guest_full_name = 'CentOS 4/5/6/7 (64 bit)' & guest_hostname = 'localhost' & guest_ip_address = '10.95.103.115' & `VM Name` = 'test6'``*\
\
*``--> @dm:addrow datastore.1 = 'netapp-dev-nfs-01' & Folder = 'User VMs,Ravi-Pisupati,TestVMs' & guest_full_name = 'CentOS 4/5/6/7 (64 bit)' & guest_hostname = 'localhost' & guest_ip_address = '10.95.103.115' & `VM Name` = 'test7'``*\
\
*``--> @dm:addrow datastore.1 = 'netapp-dev-nfs-02' & Folder = 'CFX-Drama,Capri-Demo' & guest_full_name = 'CentOS 4/5/6/7 (64 bit)' & guest_hostname = 'democloudp' & guest_ip_address = '10.95.122.212' & `VM Name` = 'test8'``*\
\
*``--> @dm:addrow datastore.1 = 'netapp-dev-nfs-02' & Folder = 'CFX-Drama,Capri-Demo' & guest_full_name = 'CentOS 4/5/6/7 (64 bit)' & guest_hostname = 'ravip-v201-platform' & guest_ip_address = '10.95.122.216' & `VM Name` = 'test9'``*\
\
*``--> @dm:addrow datastore.1 = 'netapp-dev-nfs-02' & Folder = 'CFX-Drama,Capri-Demo' & guest_full_name = 'CentOS 4/5/6/7 (64 bit)' & guest_hostname = 'cfxautomatesvc' & guest_ip_address = '10.95.125.116' & `VM Name` = 'test10'``*\
\
*`--> @dm:groupby columns = 'Folder'`*<br>

![Pipeline code added to empty pipeline created](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-Mfj1kw7LJ8eFgnBdQSH%2F-Mfj2K6RaKruWUQVFSzY%2FScreen%20Shot%202021-07-28%20at%202.37.23%20PM.png?alt=media\&token=6c0dea1b-7601-4803-9c0d-3992f95cd0d3)

Step &#x33;**:** Click verify button to verify the pipeline. RDA will verify the pipeline without any errors (as shown below)

![Pipeline code verified ](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-Mfj2TOvwZWmtTYCqfpw%2F-Mfj2pTIErmypfKvZNdJ%2FScreen%20Shot%202021-07-28%20at%202.39.48%20PM.png?alt=media\&token=ae86f32c-7985-4d6c-bac8-93699c7c529e)

Step &#x34;**:** Click execute button to execute the pipeline. RDA will execute the pipeline without any errors (as shown below)

![Screenshot (Execution of pipeline without any errors)](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-Mfj39rj696iWNhwN_E8%2F-Mfj3dPvK7T6wFtuLjEk%2FScreen%20Shot%202021-07-28%20at%202.43.27%20PM.png?alt=media\&token=1966df5b-a0df-4f55-8ff5-4ec1b0918431)

Step 5: Verify that the output data is grouped based on the selected column (e.g. 'Folder' column from the dataset created) as shown below screenshot.

![RDA runs pipeline using function dm groupby using column 'Folder' as shown above](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-Mfj42AULrH2HI8tKYUo%2F-Mfj4VoaoTKSYGULfIz_%2FScreen%20Shot%202021-07-28%20at%202.47.11%20PM.png?alt=media\&token=e363cd49-d766-428b-b30d-8e14316f0d2e)

This function is useful when users want to group by column/columns. In addition, is useful for any numeric values.&#x20;

{% hint style="info" %}
When an agg function '**sum**' is used, it automatically applies to all eligible columns (numerical values).&#x20;
{% endhint %}
