Summarize

The summarize function in DUQL is used to perform aggregations on your data, condensing multiple rows into summary statistics. It can be used both as a top-level function and within the group function, offering flexibility in how you aggregate your data.

Syntax

As a top-level function:

summarize:
  <new_column_name>: <aggregation_function>

Within a group function:

group:
  by: <grouping_columns>
  steps:
    summarize:
      <new_column_name>: <aggregation_function>

Behavior

  1. Top-level usage: When used at the top level, summarize produces a single row summarizing the entire dataset.

  2. Within group: When used inside a group function, it produces one summary row for each unique combination of the grouping columns.

This dual behavior allows for both global summaries and group-specific summaries within the same query language.

Common Aggregation Functions

Currently, all declared aggregation functions are min, max, count, average, stddev, avg, sum and count_distinct

Examples

Top-level Summarize

This query will produce a single row with overall summary statistics for the entire sales dataset.

Summarize Within Group

This query will produce summary statistics for each unique combination of category and year.

Combined Usage

This query first summarizes data by category, then provides an overall summary of those category summaries.

Best Practices

  1. ๐ŸŽฏ Choose appropriate aggregation functions for your data types and analysis goals.

  2. ๐Ÿท๏ธ Use clear and descriptive names for your summarized columns.

  3. ๐Ÿงฎ Be aware of how null values are handled in your aggregations.

  4. ๐Ÿš€ Consider performance implications when summarizing large datasets.

  5. ๐Ÿ“Š Use top-level summarize for overall statistics and group with summarize for segmented analysis.

  6. ๐Ÿ” Validate your summary results, especially when using complex aggregation expressions.

Real-World Use Case

Here's an example of a DUQL query that uses summarize both within group and at the top level to analyze sales performance:

This query demonstrates:

  1. Filtering recent sales data

  2. Joining with product information

  3. Calculating revenue and margin

  4. Grouping by category and month, with monthly summaries

  5. Sorting the grouped results

  6. Providing an overall summary of the grouped data

The resulting sales_performance_summary dataset offers both detailed monthly performance by category and overall performance metrics, showcasing the flexibility of the summarize function in DUQL.


๐Ÿ’ก Tip: The summarize function is a versatile tool in DUQL. Use it at the top level for quick overall insights, or within group for detailed breakdowns. Combine both approaches to create comprehensive analytical queries!

Last updated

Was this helpful?