# cfxdm - dm:groupby

**dm:groupby:** This cfxdm tag 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

In the below example, for a reference, we are going to use **VMware vCenter** as an extension to query the data from VMs tag and their disk size.

Enter the below command to select **VMware vCenter VMs tag (\*vcenter:vms**). (In this example, **vcenter** name is used as a label to identify VMware vCenter extension and it's tags. The label is defined while adding the extension in cfxdx configuration file or through UI)

```
tag *vcenter:vms
```

![](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MW6k3BIp5fTzyOAvOyx%2F-MW6us2YRudI68Vogt0D%2FScreen%20Shot%202021-03-18%20at%205.38.20%20PM.png?alt=media\&token=adbaa1e5-491d-4e2f-8086-1881695dc6fd)

**Example-1:**&#x20;

Get the VM's list from the above tag and select the below columns  (as shown)

* vm\_name
* disk\_capacity\_kb
* bios\_uuid

```
data * get name as 'vm_name',disk_capacity_KB as 'disk_capacity_kb',id as 'bios_uuid'
```

Pipe the data to **dm:groupby** tag to view the data grouped by VM Name.

{% hint style="info" %}
Since '**agg**' option is not specified within the **dm:groupby** tag, it applies agg function '**count**' by default.
{% endhint %}

```
data * get name as 'vm_name',disk_capacity_KB as 'disk_capacity_kb',id as 'bios_uuid' --> dm:groupby columns = 'vm_name'
```

![](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MW79yDZWZPakMiUQlIe%2F-MW7BrfFCYO5_59TAriy%2FScreen%20Shot%202021-03-18%20at%206.57.05%20PM.png?alt=media\&token=ccae1bb3-06ae-4140-91ca-793e66a66d9e)

**Example-2:**&#x20;

Continuing with above data, lets use agg function '**sum**' to calculate total VM's disk size.&#x20;

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

```
data * get name as 'vm_name',disk_capacity_KB as 'disk_capacity_kb',id as 'bios_uuid' --> dm:groupby columns = 'vm_name' & agg = 'sum'
```

![](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MW7C95pzz-mJuXDE0KI%2F-MW7E2ELU-mkLfZt_jnL%2FScreen%20Shot%202021-03-18%20at%207.06.35%20PM.png?alt=media\&token=a7f8d89c-2c68-46ad-bb89-c6a3100428ea)
