---
title: "KEEP modifier"
slug: "keep-modifier"
updated: 2025-12-23T10:25:23Z
published: 2025-12-23T10:25:23Z
---

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

# KEEP modifier

## Description

Retains the listed Dimensions on a Block and removes all others.

## Syntax

`source_block [KEEP [aggregator] [ON RANK(&lt;dimension1&gt;)]: dimension2[, dimension3]]`

- `source_block` The Metric whose Dimensions you want to keep.
- `aggregator` The aggregation method applied to the removed Dimensions (e.g. `SUM`, `AVG`, `FIRST`, `FIRSTNONBLANK`). If omitted, the default is `SUM`.
- `ON RANK` (<dimension>) Required when KEEP retains more than one Dimension and the aggregation is `FIRST` or `FIRSTNONBLANK`. Omitting `ON RANK` in this situation produces an error. See **Examples**below.
- `dimension1` The Dimension you want to retain.
- `dimension2` Any additional Dimensions to retain, separated by a comma.

The default aggregator, if omitted, is `SUM` for objects of the Number data type. Other aggregators are described in the article [Aggregation data in formulas](/v1/docs/aggregate-data-in-formulas#aggregation-methods).

## Return type

`same as source object`

## Examples

`Revenue` is a Metric of the Number data type, with the following Dimensions: `Country`, `Product`, and `Month`.

| Case | Results |
| --- | --- |
| `Revenue[KEEP SUM: Country]` | Returns the Revenue by Country where all other Dimensions were aggregated using sum. |
| `Revenue[KEEP AVG: Month]` | Returns the Revenue by Month where all other Dimensions were aggregated using average. |
| `Revenue[KEEP FIRSTNONBLANK ON RANK(Product): Country, Month]` | Returns the Revenue by Product, Country and Month, taking the first non-blank value of the Product Dimension. The ON operator is used with the [RANK function](/v1/docs/rank-function) to define which Dimension provides the first non-blank value. |

**See also**: [REMOVE](/v1/docs/remove-modifier)
