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
Top-level usage: When used at the top level,
summarizeproduces a single row summarizing the entire dataset.Within
group: When used inside agroupfunction, 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
๐ฏ Choose appropriate aggregation functions for your data types and analysis goals.
๐ท๏ธ Use clear and descriptive names for your summarized columns.
๐งฎ Be aware of how
nullvalues are handled in your aggregations.๐ Consider performance implications when summarizing large datasets.
๐ Use top-level
summarizefor overall statistics andgroupwithsummarizefor segmented analysis.๐ 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:
Filtering recent sales data
Joining with product information
Calculating revenue and margin
Grouping by category and month, with monthly summaries
Sorting the grouped results
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
summarizefunction is a versatile tool in DUQL. Use it at the top level for quick overall insights, or withingroupfor detailed breakdowns. Combine both approaches to create comprehensive analytical queries!
Last updated
Was this helpful?