Skip to main content

AQL Functions Cheatsheet

Every AQL function in one place. Use this page to scan; jump to the dedicated reference page for full signatures, parameter details, and examples.

See also: Operators Cheatsheet · AQL Functions Overview.

Table Function

FunctionSyntaxPurpose
selectselect(table, field1, [field2, ...])Returns a table containing only the specified fields.
groupgroup(table, dimension1, [dimension2, ...])Returns a table grouped by one or more specified dimensions.
filterfilter(table, condition1, [condition2, ...])Returns a table containing only the rows that satisfy one or more specified conditions.
uniqueunique(dimension1, [dimension2, ...])Returns a table with all unique combinations of the specified dimensions.
toptop(n, dimension, by: metric, [logic])Returns the top N values of a specified dimension based on a metric.
bottombottom(n, dimension, by: metric, [logic])Returns the bottom N values of a specified dimension based on a metric.

Condition Function

FunctionSyntaxPurpose
wherewhere(metric, condition1, [condition2, ...])Calculates a metric with specified conditions applied.

Aggregate Function

FunctionSyntaxPurpose
countcount([table], expression)Counts the total number of items in a group, excluding NULL values.
count_ifcount_if([table], condition)Counts the total rows from one table that satisfy the given condition.
count_distinctcount_distinct([table], expression)Counts the total number of distinct items in a group, excluding NULL values.
approx_count_distinctapprox_count_distinct([table], expression)Counts the approximate number of distinct items in a group, excluding NULL values.
averageaverage([table], expression)Calculates the average of values in a group, excluding NULL values.
minmin([table], expression)Returns the item in the group with the smallest value, excluding NULL values.
maxmax([table], expression)Returns the item in the group with the largest value, excluding NULL values.
sumsum([table], expression)Calculates the sum of values in the group, excluding NULL values.
medianmedian([table], expression)Computes the median of the values in the group, excluding NULL values.
stdevstdev([table], expression)Computes the sample standard deviation of the values in the group, excluding NULL values.
stdevpstdevp([table], expression)Computes the population standard deviation of the values in the group, excluding NULL values.
varvar([table], expression)Returns the sample variance of the values in the group, excluding NULL values.
varpvarp([table], expression)Returns the population variance of the values in the group, excluding NULL values.
string_aggstring_agg([table], expression, [sep: _sep], [distinct: _distinct], [order: _order])Returns a text that is the concatenation of all values of the expression.
corrcorr(table, field1, field2)Returns the Pearson correlation coefficient of two number fields in the table.
max_bymax_by(table, value, by)Returns the value of value from the row where by is maximum.
min_bymin_by(table, value, by)Returns the value of value from the row where by is minimum.
percentile_contpercentile_cont([table], expression, percentile)Returns the value at the given percentile of the sorted expression values, interpolating between adjacent values if needed.
percentile_discpercentile_disc([table], expression, percentile)Returns the value at the given percentile of the sorted expression values.

Logical Function

FunctionSyntaxPurpose
casecase(when: condition, then: value, [when: condition_expr, then: value, ...], [else: value])Returns the value associated with the first condition that evaluates to true.
andand(condition, ...)Returns true only when all specified conditions are true.
oror(condition, ...)Returns true when at least one of the specified conditions is true.
notnot(condition)Logical NOT takes a single truefalse expression and returns true when the expression is false.

Relationship Function

FunctionSyntaxPurpose
with_relationshipswith_relationships(metric, relationship1, [relationship2, ...])Calculates a metric using specific relationships that are not active by default.

Level Of Detail Function

FunctionSyntaxPurpose
of_allof_all(metric, [model, dimension, ...], [keep_filters: false])Returns a metric evaluated without certain dimensions or grains.
keep_grainskeep_grains(metric, [model, dimension, ...], [keep_filters: false])Calculates a metric only against the specified dimensions or grains, ignoring all other dimensions.
dimensionalizedimensionalize(metric, [dimension, ...])Calculates a metric at a specific Level of Detail (LoD), regardless of the outer query context.
percent_of_totalpercent_of_total(metric, total_type)Calculates the percentage of a metric relative to a specified total type.

Time-based Function

FunctionSyntaxPurpose
running_totalrunning_total(metric, [running_dimension, ...], [keep_filters: false])Calculates a running total of a metric along specified dimensions from the starting point to the current period.
period_to_dateperiod_to_date(metric, date_part, date_dimension)Calculates a metric from the beginning of a specified time period (year, quarter, month, etc.) to the current date.
exact_periodexact_period(metric, time_dimension, time_range)Calculates a metric within a custom time period.
relative_periodrelative_period(metric, time_dimension, offset)Calculates a metric in the active time range shifted by a specified interval.
trailing_periodtrailing_period(metric, date_dimension, period)Calculates a metric over a specific number of date periods up to the current period.

Window Function

FunctionSyntaxPurpose
rankrank(order: order_expr, ..., [partition: partition_expr, ...])Returns the rank of rows within a partition of a table.
dense_rankdense_rank(order: order_expr, ..., [partition: partition_expr, ...])Returns the rank of rows within a partition of a table.
percent_rankpercent_rank(order: order_expr, ..., [partition: partition_expr, ...])Returns the relative percentile of a row within a partition of a table.
ntilentile(ranks, order: order_expr, ..., [partition: partition_expr, ...])Divides the rows within a partition into a specified number of ranked groups.
nextnext(expr, [offset], order: order_expr, ..., [partition: partition_expr, ...])Returns the value from a following row at a specified offset relative to the current row.
previousprevious(expr, [offset], order: order_expr, ..., [partition: partition_expr, ...])Returns the value from a preceding row at a specified offset relative to the current row.
first_valuefirst_value(expr, order: order_expr, ..., [partition: partition_expr, ...])Returns the value of an expression from the first row of the window frame.
last_valuelast_value(expr, order: order_expr, ..., [partition: partition_expr, ...])Returns the value of an expression from the last row of the window frame.
nth_valuenth_value(expr, index, order: order_expr, ..., [partition: partition_expr, ...])Returns the value of an expression from the Nth row of the window frame, where N is a positive integer.
window_sumwindow_sum(aggregation_expression, [range], [order: order_expression, ...], [partition: partition_expression, ...])Returns the sum of values in rows within a specified range relative to the current row.
window_countwindow_count(aggregation_expression, [range], [order: order_expression, ...], [partition: partition_expression, ...])Returns the count of values in rows within a specified range relative to the current row.
window_minwindow_min(aggregation_expression, [range], [order: order_expression, ...], [partition: partition_expression, ...])Returns the min of rows in a range relative to the current row.
window_maxwindow_max(agg_expr, [range], [order: order_expr, ...], [partition: partition_expr, ...])Returns the maximum value in rows within a specified range relative to the current row.
window_avgwindow_avg(agg_expr, [range], [order: order_expr, ...], [partition: partition_expr, ...])Returns the average of values in rows within a specified range relative to the current row.
window_stdevwindow_stdev(agg_expr, [range], [order: order_expr, ...], [partition: partition_expr, ...])Returns the sample standard deviation of values in rows within a specified range relative to the current row.
window_stdevpwindow_stdevp(agg_expr, [range], [order: order_expr, ...], [partition: partition_expr, ...])Returns the population standard deviation of values in rows within a specified range relative to the current row.
window_varwindow_var(agg_expr, [range], [order: order_expr, ...], [partition: partition_expr, ...])Returns the sample variance of values in rows within a specified range relative to the current row.
window_varpwindow_varp(agg_expr, [range], [order: order_expr, ...], [partition: partition_expr, ...])Returns the population variance of values in rows within a specified range relative to the current row.

Time Intelligence Function

FunctionSyntaxPurpose
epochepoch([datetime])Returns a Unix timestamp which is the number of seconds that have elapsed since '1970-01-01 00:00:00' UTC.
dayday(datetime_dimension)Truncates a datetime_dimension value to the first day of the day (midnight).
weekweek(datetime_dimension)Truncates a datetime_dimension value to the first day of the week.
monthmonth(datetime_dimension)Truncates a datetime_dimension value to the first day of the month.
quarterquarter(datetime_dimension)Truncates a datetime_dimension value to the first day of the quarter.
yearyear(datetime_dimension)Truncates a datetime_dimension value to the first day of the year.
hourhour(datetime_dimension)Truncates a datetime_dimension value to the first minute of the hour.
minuteminute(datetime_dimension)Truncates a datetime_dimension value to the first second of the minute.
date_truncdate_trunc(datetime_dimension, datetime_part)Truncates a datetime_dimension value to the granularity of datetime_part.
date_partdate_part(datetime_part, datetime)Extracts a specific numeric part from a date or datetime value.
year_numyear_num(datetime)Extracts the numeric year from a datetime value.
quarter_numquarter_num(datetime)Extracts the quarter number from a datetime value.
month_nummonth_num(datetime)Extracts the month number from a datetime value.
week_numweek_num(datetime)Extracts the week number from a datetime value.
dow_numdow_num(datetime)Alias for dayofweek_num, extracts the day of week number from a datetime value.
day_numday_num(datetime)Extracts the day of month number from a datetime value.
hour_numhour_num(datetime)Extracts the hour number from a datetime value.
minute_numminute_num(datetime)Extracts the minute number from a datetime value.
second_numsecond_num(datetime)Extracts the second number from a datetime value.
date_diffdate_diff(datetime_part, start, end)Calculates the difference between two dates in the specified datetime_part.
date_formatdate_format(datetime, format)Formats a date according to the specified format string.
from_unixtimefrom_unixtime(number)Converts a Unix timestamp (seconds since epoch) to a datetime value.
last_daylast_day(datetime, date_part)Returns the last day of the period for a given date.
ageage(datetime)Returns the age in years.

Null/Zero Handling Function

FunctionSyntaxPurpose
coalescecoalesce(val1, val2, ...)Returns the first non-null value in a list of expressions.
nullifnullif(val1, val2)Returns NULL if two expressions are equal, otherwise returns the first expression.
safe_dividesafe_divide(dividend, divisor)Returns the division with a safe mechanism to handle division by zero.

Mathematical Function

FunctionSyntaxPurpose
absabs(number)Returns the absolute value of a number, removing any negative sign and returning the non-negative magnitude.
sqrtsqrt(number)Calculates the square root of a given number.
ceilceil(number)Returns the smallest integer greater than or equal to the given number.
floorfloor(number)Returns the largest integer less than or equal to the given number.
roundround(number, [scale])Rounds a number to a specified number of decimal places.
trunctrunc(number, [scale])Truncates a number to a specified number of decimal places, removing digits beyond the specified scale.
expexp(number)Returns the value of the mathematical constant e (Euler's number) raised to the power of the given number.
lnln(number)Calculates the natural logarithm (base e) of a given number.
log10log10(number)Calculates the base 10 logarithm of a given number.
log2log2(number)Calculates the base 2 logarithm of a given number.
powpow(base, exponent)Raises a base number to the power of an exponent.
modmod(dividend, divisor)Returns the remainder of a division operation.
divdiv(dividend, divisor)Returns the integer quotient of a division operation.
signsign(number)Returns the sign of a number: 1 for positive, -1 for negative, and 0 for zero.
radiansradians(degrees)Converts degrees to radians.
pipi()Returns the mathematical constant π (pi).
acosacos(number)Returns the arccosine (inverse cosine) of a number.
asinasin(number)Returns the arcsine (inverse sine) of a number.
atanatan(number)Returns the arctangent (inverse tangent) of a number.
atan2atan2(y, x)Returns the two-argument arctangent, which computes the angle between the positive x-axis and the point given by the coordinates (x, y).
coscos(number)Returns the cosine of a number.
sinsin(number)Returns the sine of a number.
tantan(number)Returns the tangent of a number.
cotcot(number)Returns the cotangent of a number.

Miscellaneous Function

FunctionSyntaxPurpose
castcast(expr, type)Returns the input value casted to the specified data type.
concatconcat(text, [text ...])Returns the concatenated string of multiple strings.
findfind(text, substring)Returns the 1-based index of the first occurrence of a substring within a text string.
leftleft(text, length)Returns the leftmost characters of a text string, up to the specified length.
rightright(text, length)Returns the rightmost characters of a text string, up to the specified length.
midmid(text, start, length)Extracts a substring of a specified length from a text string, starting at a given position (1-based).
lenlen(text)Returns the length of a text string (number of characters).
lowerlower(text)Converts a text string to lowercase.
upperupper(text)Converts a text string to uppercase.
trimtrim(text)Removes leading and trailing whitespace from a text string.
ltrimltrim(text)Removes leading whitespace from a text string.
rtrimrtrim(text)Removes trailing whitespace from a text string.
lpadlpad(text, length, pad_string)Pads the left side of a text string with a specified pad string until it reaches the specified length.
rpadrpad(text, length, pad_string)Pads the right side of a text string with a specified pad string until it reaches the specified length.
replacereplace(text, old_substring, new_substring)Replaces all occurrences of a substring within a text string with a new substring.
split_partsplit_part(text, delimiter, part_number)Splits a text string into parts based on a delimiter and returns the specified part (1-based).
regexp_extractregexp_extract(text, regex, [occurrence], [group: _group], [flags: _flags])Extracts a substring from a text string that matches a regular expression pattern.
regexp_likeregexp_like(text, regex, [flags: _flags])Checks if a text string matches a regular expression pattern.
regexp_replaceregexp_replace(text, regex, substitute, [flags: _flags])Replaces substrings in a text that match a regular expression pattern with a specified replacement text.
is_at_levelis_at_level(dimension)Returns true if the specified dimension is active in the Level of Detail (LoD) context, else false.

AI Function

FunctionSyntaxPurpose
ai_completeai_complete(model, prompt)Queries an AI model with a text prompt and returns the generated response.
ai_similarityai_similarity(text1, text2)Calculates the semantic similarity between two text strings.
ai_classifyai_classify(text, category1, category2, ...categories)Classifies text into one of the provided categories using AI.
ai_summarizeai_summarize(content)Generates a concise summary of the provided text content using AI.

SQL Passthrough Function

FunctionSyntaxPurpose
sql_textsql_text('FUNCTION_NAME', param1, param2, ...)Calls a native SQL function that returns a text/string value.
sql_numbersql_number('FUNCTION_NAME', param1, param2, ...)Calls a native SQL function that returns a numeric value.
sql_datetimesql_datetime('FUNCTION_NAME', param1, param2, ...)Calls a native SQL function that returns a datetime value.
sql_datesql_date('FUNCTION_NAME', param1, param2, ...)Calls a native SQL function that returns a date value.
sql_truefalsesql_truefalse('FUNCTION_NAME', param1, param2, ...)Calls a native SQL function that returns a boolean/truefalse value.
agg_textagg_text(table, 'FUNCTION_NAME', param1, param2, ...)Calls a native SQL aggregate function that returns a text/string value.
agg_numberagg_number(table, 'FUNCTION_NAME', param1, param2, ...)Calls a native SQL aggregate function that returns a numeric value.
agg_datetimeagg_datetime(table, 'FUNCTION_NAME', param1, param2, ...)Calls a native SQL aggregate function that returns a datetime value.
agg_dateagg_date(table, 'FUNCTION_NAME', param1, param2, ...)Calls a native SQL aggregate function that returns a date value.
agg_truefalseagg_truefalse(table, 'FUNCTION_NAME', param1, param2, ...)Calls a native SQL aggregate function that returns a boolean/truefalse value.

Open Markdown
Let us know what you think about this document :)