Skip to main content

aggregate()

Use this when you want to perform statistical calculations such as averages and maximum values.

Available Keys

Key NameDescriptionOptionalNotes
whereSpecify retrieval conditionsYesIf omitted, all rows are retrieved
orderBySort settingsYesIf specifying only one column, the array can be omitted
takeSet the number of records to retrieveYes
skipSet the number of records to skipYes
cursorCursor-based paginationYesSee findMany cursor for details
_avgAverage display settingsYes
_countHit count display settingsYes
_maxMaximum value display settingsYes
_minMinimum value display settingsYes
_sumSum display settingsYes
tip

In where, you can also use relation filters (some / every / none / is / isNot).

Example Sheet

Example Sheet

Explanation

Suppose you want to perform the following operations from the example above.

  • age => Calculate the average
  • age => Calculate the maximum value
  • age => Calculate the minimum value

The code would be as follows.

// gassma.{{TARGET_SHEET_NAME}}.aggregate
const result = gassma.sheet1.aggregate({
_avg: {
age: true,
},
_max: {
age: true,
},
_min: {
age: true,
},
});

The return value is in the following format.

{
_avg: { age: 33.333333333333336 },
_max: { age: 55 },
_min: { age: 20 }
}