---
title: "Grouping and aggregating metrics to create a meaningful valuation report"
slug: "grouping-and-aggregating-metrics-to-create-a-meaningful-valuation-report"
updated: 2024-09-04T13:24:30Z
published: 2024-09-04T13:24:30Z
canonical: "support.lusid.com/grouping-and-aggregating-metrics-to-create-a-meaningful-valuation-report"
---

> ## Documentation Index
> Fetch the complete documentation index at: https://support.lusid.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Grouping and aggregating metrics to create a meaningful valuation report

You can choose to group results in a valuation report by one or more metrics. If you do, you can aggregate grouped values for numeric metrics using mathematical operations such as `Sum`, `Proportion` and `Average`. [Find out more about metrics and valid operations](/v1/docs/what-is-a-metric).

The metrics it makes sense to group by and aggregate values for are highly dependent on the kind of valuation report you want to produce.

Consider the example of [this demo transaction portfolio](/v1/docs/creating-a-strategy-based-transaction-portfolio), which has holdings divided into Growth and Income strategies, and BP and GBP in both:

![](https://cdn.document360.io/d575ad81-c0ed-4980-bbd1-d59ac5c3de82/Images/Documentation/928d97ef-1e71-431a-bd57-c17ee3c0c2e9.png)

## Valuing without grouping

To perform a standard valuation of this portfolio, we might call the [GetValuation](https://www.lusid.com/docs/api#operation/GetValuation) API with the following request:

- The `groupBy` field is omitted to report one result per holding.
- The `Value` for each of a meaningful set of metrics is requested.
- The PV metric (`Valuation/PvInPortfolioCcy`) is requested twice, once with its raw `Value` and once calculated as a `Proportion`:

```json
curl -X POST "https://<your-domain>.lusid.com/api/api/aggregation/$valuation"
  -H "Authorization: Bearer <your-API-access-token>"
  -H "Content-Type: application/json-patch+json"
  -d '{
    "portfolioEntityIds": [ {"scope": "FBNUniversity", "code": "Module-3-1", "portfolioEntityType": "SinglePortfolio"} ],
    "valuationSchedule": {"effectiveAt": "2023-02-01T00:00:00.0000000+00:00"},
    "recipeId": {"scope": "FBNUniversity", "code": "Module-3-1Recipe"},
    "metrics": [
      {"key": "Instrument/default/Name", "op": "Value"},                            # Reports the friendly name of the underlying instrument
      {"key": "Valuation/EffectiveAt", "op": "Value"},                              # Confirms the valuation date
      {"key": "Holding/default/Units", "op": "Value"},                              # Reports the number of units held
      {"key": "Holding/Cost/Pfolio", "op": "Value"},                                # Calculates cost in GBP (the portfolio currency)
      {"key": "Quotes/Price", "op": "Value"},                                       # Retrieves market price from Quote Store
      {"key": "Valuation/PvInPortfolioCcy", "op": "Value"},                         # Calculates PV in GBP
      {"key": "Valuation/PvInPortfolioCcy", "op": "Proportion"},                    # Calculates PV as %
      {"key": "Valuation/PnL/Unrealised/PfolioCcy", "op": "Value"},                 # Calculates PnL in GBP (PV - Cost)
      {"key": "Transaction/FBNUniversity/InvestmentStrategy", "op": "Value"}        # Custom property (SHK) reporting the strategy
    ]
  }'
```

The response might look like this (transformed to a table and with columns renamed for simplicity). Note one result is produced per holding, so BP and GBP are reported twice, once per strategy:

![](https://cdn.document360.io/d575ad81-c0ed-4980-bbd1-d59ac5c3de82/Images/Documentation/6a6d123b-afa7-42f5-bd38-4b42e0d65fec.png)

## Grouping by underlying instrument

We can group by [LUID](/v1/docs/what-is-a-lusid-instrument-id-or-luid) to produce a single result for BP and GBP. To aggregate grouped values, we can `Sum` metrics where it makes sense to do so, for example for units, cost, PV and PnL. It doesn't make sense to `Sum` market prices, so we might choose to `Average` these instead:

```json
curl -X POST "https://<your-domain>.lusid.com/api/api/aggregation/$valuation"
  -H "Authorization: Bearer <your-API-access-token>"
  -H "Content-Type: application/json-patch+json"
  -d '{
    "portfolioEntityIds": [ {"scope": "FBNUniversity", "code": "Module-3-1", "portfolioEntityType": "SinglePortfolio"} ],
    "valuationSchedule": {"effectiveAt": "2023-02-01T00:00:00.0000000+00:00"},
    "recipeId": {"scope": "FBNUniversity", "code": "Module-3-1Recipe"},
    "groupBy": ["Instrument/default/LusidInstrumentId"],
    "metrics": [
      {"key": "Instrument/default/Name", "op": "Value"},                          # Reports the friendly name of the underlying instrument
      {"key": "Valuation/EffectiveAt", "op": "Value"},                            # Confirms the valuation date
      {"key": "Holding/default/Units", "op": "Sum"},                              # Sums the number of units held
      {"key": "Holding/Cost/Pfolio", "op": "Sum"},                                # Sums cost in GBP (the portfolio currency)
      {"key": "Quotes/Price", "op": "Average"},                                   # Averages market price
      {"key": "Valuation/PvInPortfolioCcy", "op": "Sum"},                         # Sums PV in GBP
      {"key": "Valuation/PvInPortfolioCcy", "op": "Proportion"},                  # Calculates PV as %
      {"key": "Valuation/PnL/Unrealised/PfolioCcy", "op": "Sum"},                 # Sums PnL in GBP (PV - Cost)
      {"key": "Transaction/FBNUniversity/InvestmentStrategy", "op": "Value"}      # Custom property (SHK) reporting the strategy
    ]
  }'
```

The response might look like this. Note that BP and GBP are reported once, and values for these holdings have been aggregated:

![](https://cdn.document360.io/d575ad81-c0ed-4980-bbd1-d59ac5c3de82/Images/Documentation/8e6c7c87-35a2-4265-b530-4cc721858696.png)

## Grouping by strategy

We can group by the portfolio's [sub-holding key](/v1/docs/how-do-i-register-sub-holding-keys-shks-with-a-portfolio) (SHK) to produce a result for each strategy. It no longer makes sense to report the instrument name or market price, so those metrics are omitted. Attempting to `Sum` units causes an [aggregation error](/v1/docs/troubleshooting-valuation-errors#aggregation-errors), since LUSID cannot aggregate units of a currency with units of equities, so this metric is also omitted:

```json
curl -X POST "https://<your-domain>.lusid.com/api/api/aggregation/$valuation"
  -H "Authorization: Bearer <your-API-access-token>"
  -H "Content-Type: application/json-patch+json"
  -d '{
    "portfolioEntityIds": [ {"scope": "FBNUniversity", "code": "Module-3-1", "portfolioEntityType": "SinglePortfolio"} ],
    "valuationSchedule": {"effectiveAt": "2023-02-01T00:00:00.0000000+00:00"},
    "recipeId": {"scope": "FBNUniversity", "code": "Module-3-1Recipe"},
    "groupBy": ["Transaction/FBNUniversity/InvestmentStrategy"],
    "metrics": [
      {"key": "Valuation/EffectiveAt", "op": "Value"},                            # Confirms the valuation date
      {"key": "Holding/Cost/Pfolio", "op": "Sum"},                                # Sums cost in GBP (the portfolio currency)
      {"key": "Valuation/PvInPortfolioCcy", "op": "Sum"},                         # Sums PV in GBP
      {"key": "Valuation/PvInPortfolioCcy", "op": "Proportion"},                  # Calculates PV as %
      {"key": "Valuation/PnL/Unrealised/PfolioCcy", "op": "Sum"},                 # Sums PnL in GBP (PV - Cost)
      {"key": "Transaction/FBNUniversity/InvestmentStrategy", "op": "Value"}      # Custom property (SHK) reporting the strategy
    ]
  }'
```

The response might look like this:

![](https://cdn.document360.io/d575ad81-c0ed-4980-bbd1-d59ac5c3de82/Images/Documentation/56f90c62-34e7-48c8-95a1-7abb946b5817.png)

## Grouping by date

We can group by the valuation date to report a total for the portfolio as a whole. It no longer makes sense to report the `Proportion` of PV (which is always 100%), nor strategy names, so these metrics are omitted:

```json
curl -X POST "https://<your-domain>.lusid.com/api/api/aggregation/$valuation"
  -H "Authorization: Bearer <your-API-access-token>"
  -H "Content-Type: application/json-patch+json"
  -d '{
    "portfolioEntityIds": [ {"scope": "FBNUniversity", "code": "Module-3-1", "portfolioEntityType": "SinglePortfolio"} ],
    "valuationSchedule": {"effectiveAt": "2023-02-01T00:00:00.0000000+00:00"},
    "recipeId": {"scope": "FBNUniversity", "code": "Module-3-1Recipe"},
    "groupBy": ["Valuation/EffectiveAt"],
    "metrics": [
      {"key": "Valuation/EffectiveAt", "op": "Value"},                        # Confirms the valuation date
      {"key": "Holding/Cost/Pfolio", "op": "Sum"},                            # Sums cost in GBP (the portfolio currency)
      {"key": "Valuation/PvInPortfolioCcy", "op": "Sum"},                     # Sums PV in GBP
      {"key": "Valuation/PnL/Unrealised/PfolioCcy", "op": "Sum"}              # Sums PnL in GBP (PV - Cost)
    ]
  }'
```

The response might look like this:

![](https://cdn.document360.io/d575ad81-c0ed-4980-bbd1-d59ac5c3de82/Images/Documentation/585333ea-2c00-4874-8a15-2f462740fbf6.png)
