--- title: "Tutorial: Grouping and aggregating metrics to create a meaningful valuation report" slug: "grouping-and-aggregating-metrics-to-create-a-meaningful-valuation-report" tags: ["metric", "groupBy", "Sum", "Proportion", "aggregation"] updated: 2026-10-20T10:57:02Z published: 2026-10-20T10:57:02Z 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. # Tutorial: 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](/v1/docs/which-metrics-can-i-include-in-my-valuation-report). If you do, you can aggregate grouped values for numeric metrics using [mathematical operations](/v1/docs/performing-operations-on-metrics) such as `Sum`, `Proportion` and `Average`. 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?sv=2026-02-06&spr=https&st=2026-11-04T02%3A21%3A25Z&se=2026-11-04T03%3A21%3A25Z&sr=c&sp=r&sig=BjtdvvDHs8gFKRq1%2FPAJDrB1yb2PhGvOL26s%2FKNO3F8%3D) ## 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://.lusid.com/api/api/aggregation/$valuation"  -H "Authorization: Bearer "  -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": "ProfitAndLoss/Total/PortfolioCcy", "op": "Value", "options": {"Window": "YTD"}},  # Calculates PnL in GBP (PV - Cost)      {"key": "Transaction/Properties[Transaction/SHK/Strategy]", "op": "Value"}                 # Custom property (SHK) reporting the strategy    ]  }' ``` The response might look like this (transformed to a table and with columns renamed for clarity). 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?sv=2026-02-06&spr=https&st=2026-11-04T02%3A21%3A25Z&se=2026-11-04T03%3A21%3A25Z&sr=c&sp=r&sig=BjtdvvDHs8gFKRq1%2FPAJDrB1yb2PhGvOL26s%2FKNO3F8%3D) ## 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://.lusid.com/api/api/aggregation/$valuation"  -H "Authorization: Bearer "  -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": "ProfitAndLoss/Total/PortfolioCcy", "op": "Sum", "options": {"Window": "YTD"}},  # Sums PnL in GBP      {"key": "Transaction/Properties[Transaction/SHK/Strategy]", "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?sv=2026-02-06&spr=https&st=2026-11-04T02%3A21%3A25Z&se=2026-11-04T03%3A21%3A25Z&sr=c&sp=r&sig=BjtdvvDHs8gFKRq1%2FPAJDrB1yb2PhGvOL26s%2FKNO3F8%3D) ## 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. It doesn't make sense to `Sum` units either, since the result would add shares of different equities to units of cash. LUSID doesn't stop you, so this metric is also omitted: ```json curl -X POST "https://.lusid.com/api/api/aggregation/$valuation"  -H "Authorization: Bearer "  -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": "ProfitAndLoss/Total/PortfolioCcy", "op": "Sum", "options": {"Window": "YTD"}},  # Sums PnL in GBP (PV - Cost)      {"key": "Transaction/Properties[Transaction/SHK/Strategy]", "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?sv=2026-02-06&spr=https&st=2026-11-04T02%3A21%3A25Z&se=2026-11-04T03%3A21%3A25Z&sr=c&sp=r&sig=BjtdvvDHs8gFKRq1%2FPAJDrB1yb2PhGvOL26s%2FKNO3F8%3D) ## 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% for a single valuation date), nor strategy names, so these metrics are omitted: ```json curl -X POST "https://.lusid.com/api/api/aggregation/$valuation"  -H "Authorization: Bearer "  -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": "ProfitAndLoss/Total/PortfolioCcy", "op": "Sum", "options": {"Window": "YTD"}}   # 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?sv=2026-02-06&spr=https&st=2026-11-04T02%3A21%3A25Z&se=2026-11-04T03%3A21%3A25Z&sr=c&sp=r&sig=BjtdvvDHs8gFKRq1%2FPAJDrB1yb2PhGvOL26s%2FKNO3F8%3D)