AQL Cheatsheet - Functions
Aggregate Function
count()
Syntax
count([table], expression)
Description
Counts the total number of items in a group, excluding NULL values.
Tags
Function, Aggregate Function
Examples
orders
| count(orders.id)
orders
| count(orders.id)
| where(orders.status == 'completed')
orders
| group(orders.delivery_country)
| select(orders.delivery_country, total_orders: count(orders.id))
Inputs
- expression (Any: required): A field or an AQL expression to be evaluated in each row of the table to be aggregated.
- table (Table: optional): The table to aggregate. It's only optional when the table can be inferred from the expression.
Output
- Number: The count of non-NULL values.
Learn more
count_if()
Syntax
count_if([table], condition)
Description
Counts the total rows from one table that satisfy the given condition.
Tags
Function, Aggregate Function, Condition
Examples
orders
| count_if(orders.delivery_country == 'USA')
orders
| count_if(orders.status == 'shipped')
orders
| group(orders.delivery_country)
| select(orders.delivery_country, shipped_orders: count_if(orders.status == 'shipped'))
Inputs
- condition (Truefalse: required): A field or an AQL expression that evaluates to true or false.
- table (Table: optional): The table to aggregate. It's only optional when the table can be inferred from the expression.
Output
- Number: The count of rows that satisfy the condition.
Learn more
count_distinct()
Syntax
count_distinct([table], expression)
Description
Counts the total number of distinct items in a group, excluding NULL values.
Tags
Function, Aggregate Function
Examples
orders
| count_distinct(orders.customer_id)
customers
| count_distinct(customers.id)
| where(customers.country == 'USA')
products
| group(products.id)
| select(products.id, total_countries: count_distinct(orders.delivery_country))
Inputs
- expression (Any: required): A field or an AQL expression to be evaluated in each row of the table to be aggregated.
- table (Table: optional): The table to aggregate. It's only optional when the table can be inferred from the expression.
Output
- Number: The count of distinct non-NULL values.
Learn more
average()
Syntax
average([table], expression)
Description
Calculates the average of values in a group, excluding NULL values.
Tags
Function, Aggregate Function
Examples
orders
| average(orders.value)
orders
| average(orders.value)
| where(orders.status == 'completed')
orders
| group(orders.delivery_country)
| select(orders.delivery_country, avg_order_value: average(orders.value))
Inputs
- expression (Number: required): A field or an AQL expression to be evaluated in each row of the table to be aggregated.
- table (Table: optional): The table to aggregate. It's only optional when the table can be inferred from the expression.
Output
- Number: The average of the values.
Aliases
avg()
Learn more
min()
Syntax
min([table], expression)
Description
Returns the item in the group with the smallest value, excluding NULL values.
Tags
Function, Aggregate Function
Examples
orders
| min(orders.value)
orders
| min(orders.value)
| where(orders.status == 'completed')
orders
| group(orders.delivery_country)
| select(orders.delivery_country, min_order_value: min(orders.value))
Inputs
- expression (Any: required): A field or an AQL expression to be evaluated in each row of the table to be aggregated.
- table (Table: optional): The table to aggregate. It's only optional when the table can be inferred from the expression.
Output
- Any: The minimum value.
Learn more
max()
Syntax
max([table], expression)
Description
Returns the item in the group with the largest value, excluding NULL values.
Tags
Function, Aggregate Function
Examples
orders
| max(orders.value)
orders
| max(orders.value)
| where(orders.status == 'completed')
orders
| group(orders.delivery_country)
| select(orders.delivery_country, max_order_value: max(orders.value))
Inputs
- expression (Any: required): A field or an AQL expression to be evaluated in each row of the table to be aggregated.
- table (Table: optional): The table to aggregate. It's only optional when the table can be inferred from the expression.
Output
- Any: The maximum value.
Learn more
sum()
Syntax
sum([table], expression)
Description
Calculates the sum of values in the group, excluding NULL values.
Tags
Function, Aggregate Function
Examples
orders
| sum(orders.value)
orders
| sum(orders.value)
| where(orders.status == 'completed')
orders
| group(orders.delivery_country)
| select(orders.delivery_country, total_order_value: sum(orders.value))
Inputs
- expression (Number: required): A field or an AQL expression to be evaluated in each row of the table to be aggregated.
- table (Table: optional): The table to aggregate. It's only optional when the table can be inferred from the expression.
Output
- Number: The sum of the values.
Learn more
median()
Syntax
median([table], expression)
Description
Computes the median of the values in the group, excluding NULL values.
Tags
Function, Aggregate Function
Examples
median(orders.quantity)
orders
| median(orders.quantity)
Inputs
- expression (Number: required): A field or an AQL expression to be evaluated in each row of the table to be aggregated.
- table (Table: optional): The table to aggregate. It's only optional when the table can be inferred from the expression.
Output
- Number: The median of the values.
Learn more
stdev()
Syntax
stdev([table], expression)
Description
Computes the sample standard deviation of the values in the group, excluding NULL values.
Tags
Function, Aggregate Function
Examples
stdev(orders.value)
orders
| stdev(orders.value)
Inputs
- expression (Number: required): A field or an AQL expression to be evaluated in each row of the table to be aggregated.
- table (Table: optional): The table to aggregate. It's only optional when the table can be inferred from the expression.
Output
- Number: The sample standard deviation.
Learn more
stdevp()
Syntax
stdevp([table], expression)
Description
Computes the population standard deviation of the values in the group, excluding NULL values.
Tags
Function, Aggregate Function
Examples
stdevp(orders.value)
orders
| stdevp(orders.value)
Inputs
- expression (Number: required): A field or an AQL expression to be evaluated in each row of the table to be aggregated.
- table (Table: optional): The table to aggregate. It's only optional when the table can be inferred from the expression.
Output
- Number: The population standard deviation.
Learn more
var()
Syntax
var([table], expression)
Description
Returns the sample variance of the values in the group, excluding NULL values.
Tags
Function, Aggregate Function
Examples
var(orders.value)
orders
| var(orders.value)
Inputs
- expression (Number: required): A field or an AQL expression to be evaluated in each row of the table to be aggregated.
- table (Table: optional): The table to aggregate. It's only optional when the table can be inferred from the expression.
Output
- Number: The sample variance.
Learn more
varp()
Syntax
varp([table], expression)
Description
Returns the population variance of the values in the group, excluding NULL values.
Tags
Function, Aggregate Function
Examples
varp(orders.value)
orders
| varp(orders.value)
Inputs
- expression (Number: required): A field or an AQL expression to be evaluated in each row of the table to be aggregated.
- table (Table: optional): The table to aggregate. It's only optional when the table can be inferred from the expression.
Output
- Number: The population variance.
Learn more
string_agg()
Syntax
string_agg([table], expression, [sep: _sep], [distinct: _distinct], [order: _order])
Description
Returns a text that is the concatenation of all values of the expression.
Tags
Function, Aggregate Function
Examples
string_agg(products.name)
string_agg(products.name, sep: ', ')
string_agg(products.name, sep: ', ', distinct: true)
string_agg(products.name, order: 'asc')
string_agg(products.name, order: 'desc')
Inputs
- expression (Text: required): A field or an AQL expression to be evaluated in each row of the table to be aggregated.
- table (Table: optional): The table to aggregate. It's only optional when the table can be inferred from the expression.
- _sep (Text: optional): Separator between values, default is
','. - _distinct (Truefalse: optional): If true, only distinct values are concatenated, default is
false. - _order (Text: optional): Specifies the ordering of values ('asc' or 'desc'), default is not specified.
Output
- Text: The concatenated text of values.
Learn more
corr()
Syntax
corr(table, field1, field2)
Description
Returns the Pearson correlation coefficient of two number fields in the table.
Tags
Function, Aggregate Function
Examples
corr(users, users.age, orders.value)
Inputs
- table (Table: required): The table containing the fields to correlate.
- field1 (Number: required): The first number field to correlate.
- field2 (Number: required): The second number field to correlate.
Output
- Number: The Pearson correlation coefficient between the two fields.
Learn more
max_by()
Syntax
max_by(table, value, by)
Description
Returns the value of value from the row where by is maximum.
Tags
Function, Aggregate Function
Examples
max_by(orders, orders.customer_name, orders.value)
Inputs
- table (Table: required): The table to find the maximum value in.
- value (Any: required): The field to return from the row with the maximum value.
- by (Any: required): The expression to use for determining the maximum value.
Output
- Any: The value of
valuefrom the row wherebyis maximum.
Learn more
min_by()
Syntax
min_by(table, value, by)
Description
Returns the value of value from the row where by is minimum.
Tags
Function, Aggregate Function
Examples
min_by(orders, orders.customer_name, orders.value)
Inputs
- table (Table: required): The table to find the minimum value in.
- value (Any: required): The field to return from the row with the minimum value.
- by (Any: required): The expression to use for determining the minimum value.
Output
- Any: The value of
valuefrom the row wherebyis minimum.
Learn more
percentile_cont()
Syntax
percentile_cont([table], expression, percentile)
Description
Returns the value at the given percentile of the sorted expression values, interpolating between adjacent values if needed.
Tags
Function, Aggregate Function
Examples
percentile_cont(ecommerce_users.age, 0.7)
ecommerce_users | percentile_cont(ecommerce_users.age, 0.7)
unique(ecommerce_users.id) | percentile_cont(total_value, 0.7)
Inputs
- expression (Any: required): A field or an AQL expression to be evaluated.
- table (Table: optional): The table to aggregate. It's only optional when the table can be inferred from the expression.
- percentile (Number: required): The percentile to compute. Must be a value between 0 and 1.
Output
- Any: The percentile value.
Learn more
percentile_disc()
Syntax
percentile_disc([table], expression, percentile)
Description
Returns the value at the given percentile of the sorted expression values. If the percentile falls between two values, a discrete value will be returned (the logic to select the value is database dependent).
Tags
Function, Aggregate Function
Examples
percentile_disc(ecommerce_users.age, 0.7)
ecommerce_users | percentile_disc(ecommerce_users.age, 0.7)
unique(ecommerce_users.id) | percentile_disc(count(ecommerce_orders.id), 0.7)
Inputs
- expression (Any: required): A field or an AQL expression to be evaluated.
- table (Table: optional): The table to aggregate. It's only optional when the table can be inferred from the expression.
- percentile (Number: required): The percentile to compute. Must be a value between 0 and 1.
Output
- Any: The percentile value.
Learn more
Condition Function
where()
Syntax
where(metric, condition1, [condition2, ...])
metric | where(condition1, [condition2, ...])
Description
Calculates a metric with specified conditions applied. The where function allow applying conditions to a metric without needing to manually modifying its original definition and filters data at the source before any calculations occur. It works similar to Dashboard Filters.
Difference vs filter: where pushes conditions down to the target model before calculations begin. In contrast, filter evaluates conditions locally after retrieving the data. Due to this key difference, condition in where can only target pre-defined dimension in modeling, and only support some form of conditions. For more information, please check the full documentation.
Tags
Function, Metric Function, Condition Function, Condition
Examples
total_order_value
| where(orders.status == 'completed')
total_order_value
| where(users.id in top(5, users.id, by: count(orders.id)))
sum(orders.value)
| where(orders.created_at matches @(last 30 days))
Inputs
- metric (Any: required): The original metric to which the condition will be applied.
- condition1 (Condition: required): The condition to restrict the metric calculation.
- [condition2, ...] (Condition: optional, repeatable): Additional conditions to apply.
Output
- Any: The original metric calculated with the specified conditions applied.
Learn more
Level Of Detail Function
of_all()
Syntax
of_all(metric, [model, dimension, ...], [keep_filters: false])
metric | of_all([model, dimension, ...], [keep_filters: false])
Description
Returns a metric evaluated without certain dimensions or grains. The of_all function removes specified dimensions from the calculation context. It is commonly used for calculating percent of total and enables comparisons between metrics at different Levels of Detail (LoD). The function has aliases exclude_grains and exclude that provides identical functionality.
Tags
Function, Metric Function, Level of Detail Function
Examples
order_value / (
order_value
| of_all(order_items.country)
)
count(orders.id)
| of_all(orders.category)
order_value - (avg(unique(order_items.country)
| select(order_value))
| of_all(order_items.country))
Inputs
- metric (Any: required): The metric to exclude dimensions from.
- model (Model: optional, repeatable): Model whose dimensions should be excluded.
- dimension (Dimension: optional, repeatable): Specific dimensions to exclude.
- keep_filters (Truefalse: optional): Whether to keep filters applied on excluded dimensions. Default is false.
Output
- Any: The original metric calculation without the specified dimensions.
Aliases
exclude_grains(), exclude()
Learn more
keep_grains()
Syntax
keep_grains(metric, [model, dimension, ...], [keep_filters: false])
metric | keep_grains([model, dimension, ...], [keep_filters: false])
Description
Calculates a metric only against the specified dimensions or grains, ignoring all other dimensions. The keep_grains function ensures that calculations maintain a consistent level of detail, prevents additional query fields from affecting the metric, and works only with dimensions already present in the context. Note that it will not add the grains to the Level of Detail context if they aren't present before calling keep_grains.
Tags
Function, Metric Function, Level of Detail Function
Aliases
keep()
Examples
// This keeps the grain of the entire user model during the metric calculation
sum(order_items.order_value)
| keep_grains(users)
average_order_value
| keep_grains(users.id)
Inputs
- metric (Any: required): The input metric to modify.
- model (Model: optional, repeatable): Model whose dimensions should be kept.
- dimension (Dimension: optional, repeatable): Specific dimensions to keep.
- keep_filters (Truefalse: optional): Whether to keep filters applied on excluded dimensions. Default is false.
Output
- Any: The original metric calculation using only the specified dimensions.
Learn more
dimensionalize()
Syntax
dimensionalize(metric, [dimension, ...])
metric | dimensionalize([dimension, ...])
Description
Calculates a metric at a specific Level of Detail (LoD), regardless of the outer query context. The dimensionalize function evaluates metrics at a fixed grain and turns the result into a dimension value. It is commonly used for cohort analysis and customer lifetime value calculations, and only works inside dimension definitions.
Difference vs keep_grains: Unlike keep_grains which retains specified grains in metric calculation, dimensionalize evaluates the calculation at specified grains and converts it into a dimension value. It only works inside dimension definitions.
Tags
Function, Metric Function, Level of Detail Function
Examples
sum(orders.amount)
| dimensionalize(users.id)
min(users.created_at | month())
| dimensionalize(users.id)
Inputs
- metric (Any: required): The metric to evaluate at a fixed grain.
- dimension (Dimension: optional, repeatable): The dimension(s) to use as the Level of Detail.
Output
- Any: The metric value at the specified granularity as a dimension value.
Learn more
percent_of_total()
Syntax
percent_of_total(metric, total_type)
Description
Calculates the percentage of a metric relative to a specified total type.
Tags
Function, Metric Function, Level of Detail Function
Examples
percent_of_total(sum(orders.revenue), 'grand_total')
// In a pivot table with years as rows and categories as columns
percent_of_total(sum(orders.revenue), 'row_total')
// In a pivot table with years as rows and categories as columns
percent_of_total(sum(orders.revenue), 'column_total')
// Same as row_total
percent_of_total(sum(orders.revenue), 'x_axis_total')
// Same as column_total
percent_of_total(sum(orders.revenue), 'legend_total')
Inputs
- metric (Any: required): A metric or aggregation expression to calculate the percentage for.
- total_type (String: required): The type of total to use as denominator:
'row_total'or'x_axis_total': Percentage of row total'column_total'or'legend_total': Percentage of column total'grand_total': Percentage of overall total
Output
- Number: A percentage value (0-100) representing the metric's proportion of the specified total.
Learn more
Logical Function
case()
Syntax
case(when: condition, then: value, [when: condition_expr, then: value, ...], [else: value])
Description
Returns the value associated with the first condition that evaluates to true. Note that the return types of all then and else expressions must be consistent.
Tags
Function, Logical Function, Condition
Examples
case(
when: users.gender == 'm', then: 'male',
when: users.gender == 'f', then: 'female',
else: 'others'
)
Inputs
- when (Truefalse: required): The condition to evaluate.
- then (Any: required): The value to return if the condition is met.
- else (Any: optional): The value to return if no conditions are met.
Output
- Any: The value returned based on the first met condition, or the else value if provided and no conditions are met.
Learn more
and()
Syntax
and(condition, ...)
Description
Returns true only when all specified conditions are true.
Tags
Function, Logical Function, Condition
Examples
and(products.id >= 2, products.id <= 8)
Inputs
- condition (Truefalse: required, repeatable): The conditions to AND together.
Output
- Truefalse: Returns true if all input conditions are true, else false.
Learn more
or()
Syntax
or(condition, ...)
Description
Returns true when at least one of the specified conditions is true.
Tags
Function, Logical Function, Condition
Inputs
- condition (Truefalse: required, repeatable): The conditions to OR together.
Output
- Truefalse: Returns true if any input condition is true, else false.
Examples
or(products.id <= 2, products.id >= 8)
Learn more
not()
Syntax
not(condition)
Description
Logical NOT takes a single truefalse expression and returns true when the expression is false.
Tags
Function, Logical Function, Condition
Examples
not(is(products.id, null))
Inputs
- condition_expr (Truefalse: required): The condition to negate.
Output
- Truefalse: Returns true if the input condition is false, else false.
Learn more
Time-based Function
running_total()
Syntax
running_total(metric, [running_dimension, ...], [keep_filters: false])
metric | running_total([running_dimension, ...], [keep_filters: false])
Description
Calculates a running total of a metric along specified dimensions from the starting point to the current period. By default, the running total is calculated after filtering (keep_filters: true). To calculate a running total of all data, ignoring any filters on the running dimensions, you can set keep_filters: false.
Tags
Function, Metric Function, Time-based Function, Cumulative Calculation, Moving Calculation
Examples
running_total(orders.total_orders, orders.created_at)
running_total(orders.total_orders, orders.created_at, orders.status)
running_total(orders.total_orders, orders.created_at, keep_filters: false)
Inputs
- metric (Any: required): The metric to calculate the running total for.
- running_dimension (Dimension: optional, repeatable): The dimension(s) to run the calculation along. If not specified, the calculation will run along all date dimensions in the exploration.
- keep_filters (Truefalse: optional): Whether to keep the filters applied on the running dimensions. Default is true.
Output
- Any: A new metric that runs along the specified dimension(s).
Learn more
period_to_date()
Syntax
period_to_date(metric, date_part, date_dimension)
metric | period_to_date(date_part, date_dimension)
Description
Calculates a metric from the beginning of a specified time period (year, quarter, month, etc.) to the current date. This function is commonly used to calculate Year-to-Date (YTD), Quarter-to-Date (QTD), or Month-to-Date (MTD) metrics.
Note: "Current date" refers to the last date in the context of the current row, not the current month/period on your calendar.
Tags
Function, Metric Function, Time-based Function, Cumulative Calculation, Moving Calculation
Examples
count(orders.id)
| period_to_date('year', orders.created_at)
count(orders.id)
| period_to_date('month', orders.created_at)
Inputs
- metric (Any: required): The metric to apply the period_to_date function to.
- date_part (Text: required): The time period for which the metric should reset. Can be one of: 'year', 'quarter', 'month', 'week', 'day'.
- date_dimension (Dimension: required): The date dimension used to determine the reset period.
Output
- Any: The input metric calculation from the beginning of the specified time period to the current date.
Learn more
exact_period()
Syntax
exact_period(metric, time_dimension, time_range)
metric | exact_period(time_dimension, time_range)
Description
Calculates a metric within a custom time period. This function can be used to compare how a metric performs in a specific period compared to another period. It overrides any applied time filters.
Tags
Function, Metric Function, Time-based Function
Examples
exact_period(orders.total_orders, orders.created_at, @2022-07-01 - 2022-09-01)
orders.total_orders
| exact_period(orders.created_at, @2022-07-01 - 2022-09-01)
Inputs
- metric (Any: required): The metric to calculate within the custom period.
- time_dimension (Dimension: required): A pre-defined datetime/date dimension used for matching periods in the time range to the period in the dimension.
- time_range (Datetime: required): A datetime literal that specifies the exact time range, e.g.,
@2022-04-01,@2022,@(last 2 weeks).
Output
- Any: The input metric calculation for the specified custom period.
Learn more
relative_period()
Syntax
relative_period(metric, time_dimension, offset)
metric | relative_period(time_dimension, offset)
Description
Calculates a metric in the active time range shifted by a specified interval. The active time range can be the range specified in a filter (if no time dimension is active) or the time period in each row of a time dimension.
Tags
Function, Metric Function, Time-based Function
Examples
relative_period(orders.total_orders, orders.created_at, interval(-1 month))
orders.total_orders
| relative_period(orders.created_at, interval(-1 month))
// Previous month when grouped by month
orders.total_orders
| relative_period(orders.created_at, -1)
// Two quarters ago when grouped by quarter
orders.total_orders
| relative_period(orders.created_at, -2)
Inputs
- metric (Any: required): The metric to calculate within the shifted time range.
- time_dimension (Dimension: required): A pre-defined datetime/date dimension used for shifting.
- offset (Interval or Number: required): Either:
- A relative interval for shifting from the active time condition, e.g.,
interval(-1 month) - A number specifying how many periods to shift based on the current time grain, e.g.,
-1for previous period
- A relative interval for shifting from the active time condition, e.g.,
Output
- Any: The input metric calculated in the active time range shifted by the specified interval.
Learn more
trailing_period()
Syntax
trailing_period(metric, date_dimension, period)
metric | trailing_period(date_dimension, period)
Description
Calculates a metric over a specific number of date periods up to the current period. This function is commonly used to calculate metrics like Trailing 3 Months, which determines the total orders in the last 3 months up until the current month.
Note: "Current period" refers to the month/period in the context of the current row, not the current month/period on your calendar.
Tags
Function, Metric Function, Time-based Function, Cumulative Calculation, Moving Calculation
Examples
trailing_period(count(orders.id), orders.created_at, interval(3 months))
count(orders.id)
| trailing_period(orders.created_at, interval(3 months))
// Last 3 months when grouped by month
count(orders.id)
| trailing_period(orders.created_at, 3)
// Last 7 days when grouped by day
count(orders.id)
| trailing_period(orders.created_at, 7)
Inputs
- metric (Any: required): The metric to apply the trailing_period function to.
- date_dimension (Dimension: required): The date dimension used to determine the periods.
- period (Interval or Number: required): Either:
- An interval literal that specifies the number of periods to calculate (includes the current period), e.g.,
interval(3 months),interval(1 year) - A number specifying how many periods to include based on the current time grain, e.g.,
3for 3 months when grouped by month
- An interval literal that specifies the number of periods to calculate (includes the current period), e.g.,
Output
- Any: The input metric calculated over the specified number of date periods up to the current period.
Learn more
Time Intelligence Function
epoch()
Syntax
epoch([datetime])
Description
Returns a Unix timestamp which is the number of seconds that have elapsed since '1970-01-01 00:00:00' UTC.
Tags
Function, Time Intelligence Function
Examples
epoch(orders.created_at)
epoch(@2022-01-03)
Inputs
- datetime (Datetime: optional): The date or datetime to convert to a Unix timestamp. If not provided, uses the current date time.
Output
- Number: Unix timestamp representing seconds since '1970-01-01 00:00:00' UTC.
day()
Syntax
day(datetime_dimension)
datetime_dimension | day()
Description
Truncates a datetime_dimension value to the first day of the day (midnight).
Tags
Function, Time Intelligence Function
Examples
day(orders.created_at)
orders.created_at | day()
Inputs
- datetime_dimension (Datetime Dimension: required): The datetime to truncate to the day
Output
- Datetime Dimension: Truncated to the first moment of the day
week()
Syntax
week(datetime_dimension)
datetime_dimension | week()
Description
Truncates a datetime_dimension value to the first day of the week. Weeks begin on the day set in the Week Start Day Setting.
Tags
Function, Time Intelligence Function
Examples
week(orders.created_at)
orders.created_at | week()
Inputs
- datetime_dimension (Datetime Dimension: required): The datetime to truncate to the week
Output
- Datetime Dimension: Truncated to the first moment of the week
month()
Syntax
month(datetime_dimension)
datetime_dimension | month()
Description
Truncates a datetime_dimension value to the first day of the month.
Tags
Function, Time Intelligence Function
Examples
month(orders.created_at)
orders.created_at | month()
Inputs
- datetime_dimension (Datetime Dimension: required): The datetime to truncate to the month
Output
- Datetime Dimension: Truncated to the first moment of the month
quarter()
Syntax
quarter(datetime_dimension)
datetime_dimension | quarter()
Description
Truncates a datetime_dimension value to the first day of the quarter.
Tags
Function, Time Intelligence Function
Examples
quarter(orders.created_at)
orders.created_at | quarter()
Inputs
- datetime_dimension (Datetime Dimension: required): The datetime to truncate to the quarter
Output
- Datetime Dimension: Truncated to the first moment of the quarter
year()
Syntax
year(datetime_dimension)
datetime_dimension | year()
Description
Truncates a datetime_dimension value to the first day of the year.
Tags
Function, Time Intelligence Function
Examples
year(orders.created_at)
orders.created_at | year()
Inputs
- datetime_dimension (Datetime Dimension: required): The datetime to truncate to the year
Output
- Datetime Dimension: Truncated to the first moment of the year
hour()
Syntax
hour(datetime_dimension)
datetime_dimension | hour()
Description
Truncates a datetime_dimension value to the first minute of the hour.
Tags
Function, Time Intelligence Function
Examples
hour(orders.created_at)
orders.created_at | hour()
Inputs
- datetime_dimension (Datetime Dimension: required): The datetime to truncate to the hour
Output
- Datetime Dimension: Truncated to the first moment of the hour
minute()
Syntax
minute(datetime_dimension)
datetime_dimension | minute()
Description
Truncates a datetime_dimension value to the first second of the minute.
Tags
Function, Time Intelligence Function
Examples
minute(orders.created_at)
orders.created_at | minute()
Inputs
- datetime_dimension (Datetime Dimension: required): The datetime to truncate to the minute
Output
- Datetime Dimension: Truncated to the first moment of the minute
date_trunc()
Syntax
date_trunc(datetime_dimension, datetime_part)
Description
Truncates a datetime_dimension value to the granularity of datetime_part. The datetime value is rounded to the beginning of datetime_part.
Supported parts: 'day', 'week', 'month', 'quarter', 'year', 'hour', 'minute'
Tags
Function, Time Intelligence Function
Examples
date_trunc(orders.created_at, 'day')
date_trunc(orders.created_at, 'month')
date_trunc(orders.created_at, 'year')
Inputs
- datetime_dimension (Datetime Dimension: required): The datetime to truncate
- datetime_part (String: required): The granularity to truncate to
Output
- Datetime Dimension: Truncated to the beginning of the specified part
date_part()
Syntax
date_part(datetime_part, datetime)
Description
Extracts a specific numeric part from a date or datetime value. Returns the numeric representation of the specified part of the date.
Tags
Function, Time Intelligence Function
Examples
date_part('year', orders.created_at)
date_part('quarter', orders.created_at)
date_part('month', orders.created_at)
Inputs
- datetime_part (String: required): The specific part of the datetime to extract
- datetime (Datetime: required): The datetime to extract the part from
Output
- Number: Integer representing the specified part of the date
year_num()
Syntax
year_num(datetime)
datetime | year_num()
Description
Extracts the numeric year from a datetime value.
Tags
Function, Time Intelligence Function
Examples
year_num(orders.created_at)
orders.created_at | year_num()