| Title: | Time Intelligence and Customer Segmentation for Financial Analysis |
| Description: | Calculate time intelligence metrics for financial planning and analysis. 'ti' provides functions for period-over-period comparisons (year-over-year, month-over-month), period-to-date calculations (YTD, MTD, QTD), and customer segmentation (ABC analysis, cohorts). Supports standard and retail calendars (4-4-5, 4-5-4, 5-4-4) with both in-memory and database backends via 'dbplyr'. |
| Version: | 4.3.0 |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| Imports: | cli, DBI, dbplyr (≥ 2.3.0), dplyr, duckdb, glue, janitor, lubridate, purrr, rlang, S7, tibble, tidyr |
| Suggests: | testthat (≥ 3.0.0), quarto, devtools, gt, fansi, contoso (≥ 2.1.0), withr |
| Config/testthat/edition: | 3 |
| Depends: | R (≥ 4.2.0) |
| URL: | https://codeberg.org/usrbinr/ti |
| Repository: | CRAN |
| Config/roxygen2/version: | 8.1.1 |
| NeedsCompilation: | no |
| Packaged: | 2026-11-01 19:41:04 UTC; hagan |
| Author: | Alejandro Hagan [aut, cre] |
| Maintainer: | Alejandro Hagan <alejandro.hagan@outlook.com> |
| Date/Publication: | 2026-11-02 10:20:02 UTC |
ABC classification function
Description
For your group variable,
abc()will categorize which groups make up what proportion of the totals according to the category_values that you have enteredThe function returns a segment object which prints out the execution steps and actions that it will take to categorize your data
Use calculate to return the results
Usage
abc(.data, category_values, .value)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
category_values |
vector of break points between 0 and 1 |
.value |
optional: if left blank, |
Details
This function is helpful to understand which groups of make up what proportion of the cumulative contribution
If you do not provide a
.valuethen it will count the transactions per group, if you provide.valuethen it willsum()the.valueper groupThe function creates a
segmentobject, which pre-processes the data into its components
Value
abc object
Examples
contoso::sales |>
dplyr::group_by(product_key) |>
abc(c(.1,.5,.7,.96,1), .value = gross_margin)
Classify a group by proportion of a variable (A,B,C,...)
Description
This returns a table that will segment your data into A,B or C segments based on custom thresholds
Usage
abc_fn(x)
Arguments
x |
segment object |
Value
a dbi objection
Action class
Description
action carries the human-readable narrative shown by the print() methods.
value is lower-cased and passed through make_action_cli() on assignment,
which stores a named logical vector saying which of the five standard steps
(aggregate, shift, compare, proportion of total, count distinct) the
calculation performs. print_actions_steps() draws the checklist from it.
Usage
action(value = NULL, method = NA_character_)
Arguments
value |
The steps the calculation performs, e.g.
|
method |
A string describing the method used by the calculation. |
Value
An action S7 object.
All period-to-date
Description
This calculates the all-time cumulative sum of targeted value using a standard or 5-5-4 calendar respecting
any groups that are passed through with dplyr::group_by()
Use calculate to return the results
Usage
atd(
.data,
.date,
.value,
calendar_type = "standard",
fiscal_year_start = 1,
week_start = 7
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by. Must be a Date or POSIXt type. |
.value |
the value column to summarize. Must be numeric. |
calendar_type |
select either 'standard', '445', '454', or '544' calendar, see 'Details' for additional information |
fiscal_year_start |
integer 1-12, the month the fiscal year starts nearest to (default 1 = January). Only used with the retail calendars ('445', '454', '544'); the standard calendar always uses calendar years, and a message says so if you change it there. |
week_start |
integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday, the default). On the standard calendar it affects only the week functions ( |
Details
This function creates a complete calendar object that fills in any missing days, weeks, months, quarters, or years
If you provide a grouped object with
dplyr::group_by(), it will generate a complete calendar for each groupThe function creates a
tiobject, which pre-processes the data and arguments for further downstream functions
NA Handling
NA values in the
.valuecolumn propagate through cumulative sums (cumsum returns NA once an NA is encountered)NA values in the
.datecolumn are excluded from the calendar join and will not appear in resultsMissing dates (gaps in your data) are filled with 0 values, not NA
standard calendar
The standard calendar splits the year into 12 months (with 28–31 days each) and uses a 7-day week
It automatically accounts for leap years every four years to match the Gregorian calendar
5-5-4 calendar
The 5-5-4 calendar divides the fiscal year into 52 weeks (occasionally 53), organizing each quarter into two 5-week periods and one 4-week period.
This system is commonly used in retail and financial reporting
Value
ti object
See Also
Other time_intelligence:
dod(),
mom(),
momtd(),
mtd(),
mtdopm(),
pmtd(),
pqtd(),
pwtd(),
pytd(),
qoq(),
qoqtd(),
qtd(),
qtdopq(),
wow(),
wowtd(),
wtd(),
wtdopw(),
yoy(),
yoytd(),
ytd(),
ytdopy()
Examples
atd(contoso::sales,.date=order_date,.value=quantity,calendar_type="standard")
All-to-date execution function
Description
atd_fn() is the function that is called by atd() when passed through to calculate
Usage
atd_fn(x)
Arguments
x |
ti object |
Details
This is internal non exported function that is nested in ti class and is called upon when the underlying function is called
by calculate
This will return a dbi object that can converted to a tibble object with dplyr::collect()
Value
dbi object
See Also
atd() for the function's intent
Add Comprehensive Date-Based Attributes to a DBI lazy frame or tibble object
Description
This function takes a data frame and a date column and generates a wide set of derived date attributes. These include start/end dates for year, quarter, month, and week; day-of-week indicators; completed and remaining days in each time unit; and additional convenience variables such as weekend indicators.
It is designed for time-based feature engineering and is useful in reporting, forecasting, time-series modeling, and data enrichment workflows.
Usage
augment_standard_calendar(.data, .date)
Arguments
.data |
A data frame or tibble containing at least one date column. |
.date |
A column containing |
Details
The function creates the following groups of attributes:
1. Start and end dates
-
year_start_date,year_end_date -
quarter_start_date,quarter_end_date -
month_start_date,month_end_date -
week_start_date,week_end_date
2. Day-of-week fields
-
day_of_week– numeric day of the week (1–7) -
day_of_week_label– ordered factor label (e.g., Mon, Tue, …)
3. Duration fields
-
days_in_year– total days in the year interval -
days_in_quarter– total days in the quarter interval -
days_in_month– total days in the month
4. Completed/remaining days
-
days_complete_in_week,days_remaining_in_week -
days_complete_in_month,days_remaining_in_month -
days_complete_in_quarter,days_remaining_in_quarter -
days_complete_in_year,days_remaining_in_year
5. Miscellaneous
-
weekend_indicator– equals 1 if Saturday or Sunday; otherwise 0
All date-derived fields ending in _date are coerced to class Date.
Value
A dbi or tibble containing the original data along with all generated date-based attributes.
Add Comprehensive Date-Based Attributes to a DBI lazy frame
Description
This function takes a data frame and a date column and generates a wide set of derived date attributes. These include start/end dates for year, quarter, month, and week; day-of-week indicators; completed and remaining days in each time unit; and additional convenience variables such as weekend indicators.
It is designed for time-based feature engineering and is useful in reporting, forecasting, time-series modeling, and data enrichment workflows.
Usage
augment_standard_calendar_dbi(.data, .date)
Arguments
.data |
A data frame or tibble containing at least one date column. |
.date |
A column containing |
Details
The function creates the following groups of attributes:
1. Start and end dates
-
year_start_date,year_end_date -
quarter_start_date,quarter_end_date -
month_start_date,month_end_date -
week_start_date,week_end_date
2. Day-of-week fields
-
day_of_week– numeric day of the week (1–7) -
day_of_week_label– ordered factor label (e.g., Mon, Tue, …)
3. Duration fields
-
days_in_year– total days in the year interval -
days_in_quarter– total days in the quarter interval -
days_in_month– total days in the month
4. Completed/remaining days
-
days_complete_in_week,days_remaining_in_week -
days_complete_in_month,days_remaining_in_month -
days_complete_in_quarter,days_remaining_in_quarter -
days_complete_in_year,days_remaining_in_year
5. Miscellaneous
-
weekend_indicator– equals 1 if Saturday or Sunday; otherwise 0
All date-derived fields ending in _date are coerced to class Date.
Value
A dbi containing the original data along with all generated date-based attributes.
Add Comprehensive Date-Based Attributes to a Data Frame
Description
This function takes a data frame and a date column and generates a wide set of derived date attributes. These include start/end dates for year, quarter, month, and week; day-of-week indicators; completed and remaining days in each time unit; and additional convenience variables such as weekend indicators.
It is designed for time-based feature engineering and is useful in reporting, forecasting, time-series modeling, and data enrichment workflows.
Usage
augment_standard_calendar_tbl(.data, .date)
Arguments
.data |
A data frame or tibble containing at least one date column. |
.date |
A column containing |
Details
The function creates the following groups of attributes:
1. Start and end dates
-
year_start_date,year_end_date -
quarter_start_date,quarter_end_date -
month_start_date,month_end_date -
week_start_date,week_end_date
2. Day-of-week fields
-
day_of_week– numeric day of the week (1–7) -
day_of_week_label– ordered factor label (e.g., Mon, Tue, …)
3. Duration fields
-
days_in_year– total days in the year interval -
days_in_quarter– total days in the quarter interval -
days_in_month– total days in the month
4. Completed/remaining days
-
days_complete_in_week,days_remaining_in_week -
days_complete_in_month,days_remaining_in_month -
days_complete_in_quarter,days_remaining_in_quarter -
days_complete_in_year,days_remaining_in_year
5. Miscellaneous
-
weekend_indicator– equals 1 if Saturday or Sunday; otherwise 0
All date-derived fields ending in _date are coerced to class Date.
Value
A tibble containing the original data along with all generated date-based attributes.
Execute time-intelligence or segments class objects to return the underlying transformed table
Description
The calculate() function takes an object created by a time function (like ytd(), mtd(), or qtd()) or a segment function (like cohort() or abc()) and executes the underlying transformation logic.
It translates the function blueprint into an actionable query, returning the final data table.
Usage
calculate(x, ...)
## S7 method for class <ti::ti>
calculate(x, ...)
## S7 method for class <ti::segment_cohort>
calculate(x, ...)
## S7 method for class <ti::segment_abc>
calculate(x, ...)
Arguments
x |
ti object |
... |
Not used. |
Details
The TI and segment functions in ti—such as ytd() or cohort() and others—are designed to be lazy and database-friendly.
They do not perform the heavy data transformation immediately.
Instead, they return a blueprint object (of class ti,segment_abc or segment_cohort) that contains all the parameters and logic needed for the calculation.
calculate() serves as the execution engine.
When called, it interprets the blueprint and generates optimized R code or SQL code (using the dbplyr package) that is then executed efficiently on the data source, whether it's an in-memory tibble or a 'DuckDB' table.
This approach minimizes data transfer and improves performance for large datasets.
The resulting table will be sorted by the relevant date column to ensure the correct temporal ordering of the calculated metrics.
Value
dbi object
Examples
x <- ytd(contoso::sales,.date=order_date,.value=quantity,calendar_type="standard")
calculate(x)
Build a daily calendar with each day's period start date
Description
Returns one row per day with the calendar labels (year, quarter, month,
week, day) and period_date, the first day of the period of time_unit
that the day belongs to. Periods are defined by the labels, never by flooring
dates, so a period is exactly the set of days that share its labels:
standard calendar: weeks start on
week_startand week 1 is the week that contains 1 January, so only the weeks around 1 January are partial (the same convention as Excel'sWEEKNUM()). Weeks do not split at month ends; a week's month and quarter are those of its first day.retail calendars: fiscal year, quarter, month and week from
generate_retail_calendar().
The calendar starts 371 days before start_date so that the period containing
start_date is dated by its true first day, even for 53-week fiscal years.
Usage
calendar_day_sql(
.con,
start_date,
end_date,
calendar_type = "standard",
time_unit = "day",
week_start = 7,
fiscal_year_start = 1
)
Arguments
.con |
A valid DBI connection object (e.g., DuckDB, Postgres, Snowflake)
or a |
start_date |
A character string in 'YYYY-MM-DD' format or a Date object representing the start of the series. |
end_date |
A character string in 'YYYY-MM-DD' format or a Date object representing the end of the series. |
calendar_type |
One of "standard", "445", "454" or "544". |
time_unit |
A character string specifying the interval. Must be one of:
|
week_start |
Integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday). |
fiscal_year_start |
Integer 1-12, month the fiscal year starts nearest to (retail calendars only). |
Value
A tbl_lazy with columns date, year, quarter, month, week,
day and period_date.
One row per period that overlaps the requested range
Description
One row per period that overlaps the requested range
Usage
calendar_periods(day_dbi, start_date, time_unit)
Arguments
day_dbi |
Output of |
start_date |
First date of the requested range. |
time_unit |
Time unit of the periods. |
Value
A tbl_lazy with date (the period's first day) and the label
columns for time_unit, taken from that first day.
Category class
Description
category holds the cumulative cut-points used by abc() to bucket group
members. Assigning category_names derives one letter per cut-point from
category_values, so the default three cut-points become a, b and c.
Usage
category(category_values = c(0.7, 0.96, 1), category_names = NULL)
Arguments
category_values |
Numeric cumulative cut-points, all |
category_names |
Bucket labels; derived from the length of
|
Value
A category S7 object.
Cohort Analysis
Description
Database-friendly cohort analysis function.
A remake of https://github.com/PeerChristensen/cohorts, combining
cohort_table_month, cohort_table_year, and cohort_table_day into a single package.
Rewritten for database compatibility; runs entirely in SQL without writing tables.
Usage
cohort(.data, .date, .value, time_unit = "month", period_label = FALSE)
Arguments
.data |
tibble or dbi object |
.date |
date column |
.value |
id column |
time_unit |
do you want summarize the date column to 'day', 'week', 'month','quarter' or 'year' |
period_label |
do you want period labels or the dates c(TRUE , FALSE) |
Details
Groups your
.valuecolumn by shared time attributes from the.datecolumn.Assigns each member to a cohort based on their first entry in
.date.Aggregates the cohort by the
time_unitargument (day,week,month,quarter, oryear).Computes the distinct count of each cohort member over time.
Value
segment object
Internal function for the cohort segment object
Description
Internal function for the cohort segment object
Usage
cohort_fn(x)
Arguments
x |
segment object |
Value
function
Title
Description
Title
Usage
complete_standard_calendar(.data, x)
Arguments
.data |
DBI object |
x |
ti object |
Value
DBI object
Create Calendar Table
Description
create_calendar() summarizes a tibble to target time unit and completes the calendar to ensure
no missing days, month, quarter or years. If a grouped tibble is passed through it will complete the calendar
for each combination of the group
Usage
create_calendar(x, ...)
## S7 method for class <ti::ti>
create_calendar(x, ...)
Arguments
x |
ti object |
... |
Not used. |
Details
This is in internal function to make it easier to ensure data has no missing dates to
simplify the use of time intelligence functions downstream of the application.
If you want to summarize to a particular group, simply pass the tibble through to the dplyr::group_by() argument
prior to function and the function will make summarize and make a complete calendar for each group item.
Value
dbi object
Title
Description
Title
Usage
create_full_dbi(x)
Arguments
x |
ti object |
Value
DBI object
Datum class
Description
datum wraps the user's table together with the metadata every
time-intelligence function needs: which column holds the date, what calendar
the dates should be interpreted against, and how the table is grouped. Most
of its properties are read-only and computed on access from data and
date_vec, so they always reflect the current table.
Usage
datum(
data = NULL,
calendar_type = "standard",
fiscal_year_start = 1,
week_start = 7,
date_vec = NULL
)
Arguments
data |
A |
calendar_type |
One of |
fiscal_year_start |
Integer between 1 and 12 giving the month the fiscal year starts in. |
week_start |
Integer between 1 (Monday) and 7 (Sunday) giving the day weeks start on. |
date_vec |
The name of the date column, as a string. |
Value
A datum S7 object.
Additional properties
@class_name"dbi"ifdatais a database table, otherwise"tbl".@date_quodate_vecparsed to a symbol for tidy evaluation.@min_dateThe earliest value of the date column.
@max_dateThe latest value of the date column.
@date_rangeNumber of days between
min_dateandmax_date.@date_countNumber of distinct dates present in the date column.
@date_missingdate_rangeminusdate_count, i.e. gaps in the calendar.@group_indicatorTRUEifdatacarries grouping variables.@group_quoThe grouping variables as a list of symbols.
@group_vecThe grouping variables as a character vector.
@group_countNumber of grouping variables.
Detect SQL dialect from a DBI connection
Description
Detect SQL dialect from a DBI connection
Usage
detect_sql_dialect(.con)
Arguments
.con |
A DBI connection object |
Value
A character string: "snowflake", "duckdb", or "postgres"
Current period day over previous period day
Description
This calculates the daily value compared to the previous day's value using a standard or 5-5-4 calendar respecting
any groups that are passed through with dplyr::group_by()
Use calculate to return the results
Usage
dod(
.data,
.date,
.value,
calendar_type = "standard",
lag_n = 1,
fiscal_year_start = 1,
week_start = 7
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by. Must be a Date or POSIXt type. |
.value |
the value column to summarize. Must be numeric. |
calendar_type |
select either 'standard', '445', '454', or '544' calendar, see 'Details' for additional information |
lag_n |
the number of periods to lag |
fiscal_year_start |
integer 1-12, the month the fiscal year starts nearest to (default 1 = January). Only used with the retail calendars ('445', '454', '544'); the standard calendar always uses calendar years, and a message says so if you change it there. |
week_start |
integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday, the default). On the standard calendar it affects only the week functions ( |
Details
This function creates a complete calendar object that fills in any missing days, weeks, months, quarters, or years
If you provide a grouped object with
dplyr::group_by(), it will generate a complete calendar for each groupThe function creates a
tiobject, which pre-processes the data and arguments for further downstream functions
NA Handling
NA values in the
.valuecolumn propagate through cumulative sums (cumsum returns NA once an NA is encountered)NA values in the
.datecolumn are excluded from the calendar join and will not appear in resultsMissing dates (gaps in your data) are filled with 0 values, not NA
standard calendar
The standard calendar splits the year into 12 months (with 28–31 days each) and uses a 7-day week
It automatically accounts for leap years every four years to match the Gregorian calendar
5-5-4 calendar
The 5-5-4 calendar divides the fiscal year into 52 weeks (occasionally 53), organizing each quarter into two 5-week periods and one 4-week period.
This system is commonly used in retail and financial reporting
Value
ti object
See Also
Other time_intelligence:
atd(),
mom(),
momtd(),
mtd(),
mtdopm(),
pmtd(),
pqtd(),
pwtd(),
pytd(),
qoq(),
qoqtd(),
qtd(),
qtdopq(),
wow(),
wowtd(),
wtd(),
wtdopw(),
yoy(),
yoytd(),
ytd(),
ytdopy()
Examples
dod(contoso::sales,.date=order_date,.value=quantity,calendar_type='standard',lag_n=1)
Day-over-day execution function
Description
dod_fn() is the function that is called by dod() when passed through to calculate
Usage
dod_fn(x)
Arguments
x |
ti object |
Details
This is internal non exported function that is nested in ti class and is called upon when the underlying function is called
by calculate
This will return a dbi object that can converted to a tibble object with dplyr::collect()
Value
dbi object
See Also
dod() for the function's intent
Function class
Description
fn is the blueprint half of a lazy time-intelligence object. It holds the
transformation to run (fn_exec) plus the metadata that describes it,
which is what lets ytd() and friends return an object cheaply and defer the
real work to calculate().
Usage
fn(
fn_exec = function() NULL,
fn_name = NA_character_,
fn_long_name = NA_character_,
shift = NA_character_,
compare = NA_character_,
label = FALSE,
new_date_column_name = NA_character_,
lag_n = 0
)
Arguments
fn_exec |
A function taking a |
fn_name |
Short name of the calculation, e.g. |
fn_long_name |
Human-readable name, e.g. |
shift |
The period the calculation shifts by, e.g. |
compare |
The period the calculation compares against. |
label |
Whether the calculation adds a period label column. |
new_date_column_name |
Name of the date column the calculation creates. |
lag_n |
Number of periods to lag by. |
Value
An fn S7 object.
Generate a retail (4-4-5, 4-5-4, or 5-4-4) calendar mapping table
Description
Generate a retail (4-4-5, 4-5-4, or 5-4-4) calendar mapping table
Usage
generate_retail_calendar(
start_date,
end_date,
calendar_type,
fiscal_year_start = 1,
week_start = 7
)
Arguments
start_date |
Start date (Date or character YYYY-MM-DD) |
end_date |
End date (Date or character YYYY-MM-DD) |
calendar_type |
One of "445", "454", "544" |
fiscal_year_start |
Integer 1-12, month the fiscal year starts nearest to |
week_start |
Integer 1-7, day of week (1=Monday, 7=Sunday) |
Value
A tibble with columns: date, year, quarter, month, week
Explain settings that have no effect
Description
week_start and fiscal_year_start exist on every time intelligence
function because the retail calendars build every fiscal period from whole
weeks. On the standard calendar they matter much less: fiscal_year_start
does nothing, and week_start only affects the week functions and the
week column. This returns one sentence per setting that was changed from
its default but has no effect (or only relabels the week column), for
build_ti() to show as a message and print_assumptions() to print.
Usage
ignored_settings(x)
Arguments
x |
A |
Value
A named character vector, possibly empty.
Validate an input is YYYY-MM-DD format
Description
Validate an input is YYYY-MM-DD format
Usage
is_yyyy_mm_dd(x)
Arguments
x |
date column |
Value
logical
Record which of the standard steps a calculation performs
Description
Record which of the standard steps a calculation performs
Usage
make_action_cli(x)
Arguments
x |
Character vector of the steps the function performs. |
Value
A named logical vector with one element per standard step: aggregate, shift, compare, proportion of total and count distinct.
Coerce data into a DuckDB-backed lazy table
Description
Ensures the input is a database-backed object. If a data.frame is provided,
it is registered into a temporary, in-memory DuckDB instance. If already
a tbl_dbi, it is returned unchanged.
Usage
make_db_tbl(x)
Arguments
x |
A tibble, data.frame, or tbl_dbi object. |
Details
When converting a data.frame, this function preserves existing dplyr
groups. It uses DuckDB's duckdb_register, which is a virtual registration
and does not perform a physical copy of the data, making it extremely fast.
Value
A tbl_dbi object backed by DuckDB.
Current full period month over previous full period month
Description
This calculates the monthly cumulative sum of targeted value using a standard or 5-5-4 calendar respecting
any groups that are passed through with dplyr::group_by()
Use calculate to return the results
Usage
mom(
.data,
.date,
.value,
calendar_type = "standard",
lag_n = 1,
fiscal_year_start = 1,
week_start = 7
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by. Must be a Date or POSIXt type. |
.value |
the value column to summarize. Must be numeric. |
calendar_type |
select either 'standard', '445', '454', or '544' calendar, see 'Details' for additional information |
lag_n |
the number of periods to lag |
fiscal_year_start |
integer 1-12, the month the fiscal year starts nearest to (default 1 = January). Only used with the retail calendars ('445', '454', '544'); the standard calendar always uses calendar years, and a message says so if you change it there. |
week_start |
integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday, the default). On the standard calendar it affects only the week functions ( |
Details
This function creates a complete calendar object that fills in any missing days, weeks, months, quarters, or years
If you provide a grouped object with
dplyr::group_by(), it will generate a complete calendar for each groupThe function creates a
tiobject, which pre-processes the data and arguments for further downstream functions
NA Handling
NA values in the
.valuecolumn propagate through cumulative sums (cumsum returns NA once an NA is encountered)NA values in the
.datecolumn are excluded from the calendar join and will not appear in resultsMissing dates (gaps in your data) are filled with 0 values, not NA
standard calendar
The standard calendar splits the year into 12 months (with 28–31 days each) and uses a 7-day week
It automatically accounts for leap years every four years to match the Gregorian calendar
5-5-4 calendar
The 5-5-4 calendar divides the fiscal year into 52 weeks (occasionally 53), organizing each quarter into two 5-week periods and one 4-week period.
This system is commonly used in retail and financial reporting
Value
ti object
See Also
Other time_intelligence:
atd(),
dod(),
momtd(),
mtd(),
mtdopm(),
pmtd(),
pqtd(),
pwtd(),
pytd(),
qoq(),
qoqtd(),
qtd(),
qtdopq(),
wow(),
wowtd(),
wtd(),
wtdopw(),
yoy(),
yoytd(),
ytd(),
ytdopy()
Examples
mom(contoso::sales,.date=order_date,.value=quantity,calendar_type='standard',lag_n=1)
month-over-month execution function
Description
mom_fn() is the function that is called by mom() when passed through to calculate
Usage
mom_fn(x)
Arguments
x |
ti object |
Details
This is internal non exported function that is nested in ti class and is called upon when the underlying function is called
by calculate
This will return a dbi object that can converted to a tibble object with dplyr::collect()
Value
dbi object
See Also
mom() for the function's intent
Current period month to date compared to previous period month-to-date
Description
This calculates the monthly cumulative sum of targeted value using a standard or 5-5-4 calendar respecting
any groups that are passed through with dplyr::group_by()
Use calculate to return the results
Usage
momtd(
.data,
.date,
.value,
calendar_type = "standard",
lag_n = 1,
fiscal_year_start = 1,
week_start = 7
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by. Must be a Date or POSIXt type. |
.value |
the value column to summarize. Must be numeric. |
calendar_type |
select either 'standard', '445', '454', or '544' calendar, see 'Details' for additional information |
lag_n |
the number of periods to lag |
fiscal_year_start |
integer 1-12, the month the fiscal year starts nearest to (default 1 = January). Only used with the retail calendars ('445', '454', '544'); the standard calendar always uses calendar years, and a message says so if you change it there. |
week_start |
integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday, the default). On the standard calendar it affects only the week functions ( |
Details
This function creates a complete calendar object that fills in any missing days, weeks, months, quarters, or years
If you provide a grouped object with
dplyr::group_by(), it will generate a complete calendar for each groupThe function creates a
tiobject, which pre-processes the data and arguments for further downstream functions
NA Handling
NA values in the
.valuecolumn propagate through cumulative sums (cumsum returns NA once an NA is encountered)NA values in the
.datecolumn are excluded from the calendar join and will not appear in resultsMissing dates (gaps in your data) are filled with 0 values, not NA
standard calendar
The standard calendar splits the year into 12 months (with 28–31 days each) and uses a 7-day week
It automatically accounts for leap years every four years to match the Gregorian calendar
5-5-4 calendar
The 5-5-4 calendar divides the fiscal year into 52 weeks (occasionally 53), organizing each quarter into two 5-week periods and one 4-week period.
This system is commonly used in retail and financial reporting
Value
ti object
See Also
Other time_intelligence:
atd(),
dod(),
mom(),
mtd(),
mtdopm(),
pmtd(),
pqtd(),
pwtd(),
pytd(),
qoq(),
qoqtd(),
qtd(),
qtdopq(),
wow(),
wowtd(),
wtd(),
wtdopw(),
yoy(),
yoytd(),
ytd(),
ytdopy()
Examples
momtd(contoso::sales,.date=order_date,.value=quantity,calendar_type="standard", lag_n=1)
Current year to date over previous year-to-date for tibble objects
Description
momtd_fn() is the function that is called by momtd() when passed through to calculate
Usage
momtd_fn(x)
Arguments
x |
ti object |
Details
This is internal non exported function that is nested in ti class and is called upon when the underlying function is called
by calculate
This will return a dbi object that can converted to a tibble object with dplyr::collect()
Value
dbi object
See Also
momtd() for the function's intent
Current period month-to-date
Description
This calculates the monthly cumulative sum of targeted value using a standard or 5-5-4 calendar respecting
any groups that are passed through with dplyr::group_by()
Use calculate to return the results
Usage
mtd(
.data,
.date,
.value,
calendar_type = "standard",
fiscal_year_start = 1,
week_start = 7
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by. Must be a Date or POSIXt type. |
.value |
the value column to summarize. Must be numeric. |
calendar_type |
select either 'standard', '445', '454', or '544' calendar, see 'Details' for additional information |
fiscal_year_start |
integer 1-12, the month the fiscal year starts nearest to (default 1 = January). Only used with the retail calendars ('445', '454', '544'); the standard calendar always uses calendar years, and a message says so if you change it there. |
week_start |
integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday, the default). On the standard calendar it affects only the week functions ( |
Details
This function creates a complete calendar object that fills in any missing days, weeks, months, quarters, or years
If you provide a grouped object with
dplyr::group_by(), it will generate a complete calendar for each groupThe function creates a
tiobject, which pre-processes the data and arguments for further downstream functions
NA Handling
NA values in the
.valuecolumn propagate through cumulative sums (cumsum returns NA once an NA is encountered)NA values in the
.datecolumn are excluded from the calendar join and will not appear in resultsMissing dates (gaps in your data) are filled with 0 values, not NA
standard calendar
The standard calendar splits the year into 12 months (with 28–31 days each) and uses a 7-day week
It automatically accounts for leap years every four years to match the Gregorian calendar
5-5-4 calendar
The 5-5-4 calendar divides the fiscal year into 52 weeks (occasionally 53), organizing each quarter into two 5-week periods and one 4-week period.
This system is commonly used in retail and financial reporting
Value
ti object
See Also
Other time_intelligence:
atd(),
dod(),
mom(),
momtd(),
mtdopm(),
pmtd(),
pqtd(),
pwtd(),
pytd(),
qoq(),
qoqtd(),
qtd(),
qtdopq(),
wow(),
wowtd(),
wtd(),
wtdopw(),
yoy(),
yoytd(),
ytd(),
ytdopy()
Examples
mtd(contoso::sales,.date=order_date,.value=quantity,calendar_type="standard")
Month-to-date execution function
Description
mtd_fn() is the function that is called by mtd() when passed through to calculate
Usage
mtd_fn(x)
Arguments
x |
ti object |
Details
This is internal non exported function that is nested in ti class and is called upon when the underlying function is called
by calculate
This will return a dbi object that can converted to a tibble object with dplyr::collect()
Value
dbi object
See Also
mtd() for the function's intent
Current month-to-date over full previous period month
Description
This calculates the monthly cumulative sum of targeted value using a standard or 5-5-4 calendar respecting
any groups that are passed through with dplyr::group_by()
Use calculate to return the results
Usage
mtdopm(
.data,
.date,
.value,
calendar_type = "standard",
lag_n = 1,
fiscal_year_start = 1,
week_start = 7
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by. Must be a Date or POSIXt type. |
.value |
the value column to summarize. Must be numeric. |
calendar_type |
select either 'standard', '445', '454', or '544' calendar, see 'Details' for additional information |
lag_n |
the number of periods to lag |
fiscal_year_start |
integer 1-12, the month the fiscal year starts nearest to (default 1 = January). Only used with the retail calendars ('445', '454', '544'); the standard calendar always uses calendar years, and a message says so if you change it there. |
week_start |
integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday, the default). On the standard calendar it affects only the week functions ( |
Details
This function creates a complete calendar object that fills in any missing days, weeks, months, quarters, or years
If you provide a grouped object with
dplyr::group_by(), it will generate a complete calendar for each groupThe function creates a
tiobject, which pre-processes the data and arguments for further downstream functions
NA Handling
NA values in the
.valuecolumn propagate through cumulative sums (cumsum returns NA once an NA is encountered)NA values in the
.datecolumn are excluded from the calendar join and will not appear in resultsMissing dates (gaps in your data) are filled with 0 values, not NA
standard calendar
The standard calendar splits the year into 12 months (with 28–31 days each) and uses a 7-day week
It automatically accounts for leap years every four years to match the Gregorian calendar
5-5-4 calendar
The 5-5-4 calendar divides the fiscal year into 52 weeks (occasionally 53), organizing each quarter into two 5-week periods and one 4-week period.
This system is commonly used in retail and financial reporting
Value
ti object
See Also
Other time_intelligence:
atd(),
dod(),
mom(),
momtd(),
mtd(),
pmtd(),
pqtd(),
pwtd(),
pytd(),
qoq(),
qoqtd(),
qtd(),
qtdopq(),
wow(),
wowtd(),
wtd(),
wtdopw(),
yoy(),
yoytd(),
ytd(),
ytdopy()
Examples
mtdopm(contoso::sales,.date=order_date,.value=quantity,calendar_type="standard",lag_n=1)
Month-to-date over full previous month execution function
Description
mtdopm_fn() is the function that is called by mtdopm() when passed through to calculate
Usage
mtdopm_fn(x)
Arguments
x |
ti object |
Details
This is internal non exported function that is nested in ti class and is called upon when the underlying function is called
by calculate
This will return a dbi object that can converted to a tibble object with dplyr::collect()
Value
dbi object
See Also
mtdopm() for the function's intent
Period that each date belongs to
Description
Labels dates with their period in R, using the same definitions as the
calendar SQL: weeks start on week_start and week 1 contains 1 January on
the standard calendar; fiscal labels from generate_retail_calendar() on the
retail calendars.
Usage
period_keys(
dates,
time_unit,
calendar_type = "standard",
week_start = 7,
fiscal_year_start = 1
)
Arguments
dates |
A |
time_unit |
One of "day", "week", "month", "quarter" or "year". |
calendar_type |
One of "standard", "445", "454" or "544". |
week_start |
Integer 1 (Monday) to 7 (Sunday). |
fiscal_year_start |
Integer 1-12. |
Value
A character vector of period keys, one per date.
Previous period month-to-date
Description
This calculates the monthly cumulative sum of targeted value using a standard or 5-5-4 calendar respecting
any groups that are passed through with dplyr::group_by()
Use calculate to return the results
Usage
pmtd(
.data,
.date,
.value,
calendar_type = "standard",
lag_n = 1,
fiscal_year_start = 1,
week_start = 7
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by. Must be a Date or POSIXt type. |
.value |
the value column to summarize. Must be numeric. |
calendar_type |
select either 'standard', '445', '454', or '544' calendar, see 'Details' for additional information |
lag_n |
the number of periods to lag |
fiscal_year_start |
integer 1-12, the month the fiscal year starts nearest to (default 1 = January). Only used with the retail calendars ('445', '454', '544'); the standard calendar always uses calendar years, and a message says so if you change it there. |
week_start |
integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday, the default). On the standard calendar it affects only the week functions ( |
Details
This function creates a complete calendar object that fills in any missing days, weeks, months, quarters, or years
If you provide a grouped object with
dplyr::group_by(), it will generate a complete calendar for each groupThe function creates a
tiobject, which pre-processes the data and arguments for further downstream functions
NA Handling
NA values in the
.valuecolumn propagate through cumulative sums (cumsum returns NA once an NA is encountered)NA values in the
.datecolumn are excluded from the calendar join and will not appear in resultsMissing dates (gaps in your data) are filled with 0 values, not NA
standard calendar
The standard calendar splits the year into 12 months (with 28–31 days each) and uses a 7-day week
It automatically accounts for leap years every four years to match the Gregorian calendar
5-5-4 calendar
The 5-5-4 calendar divides the fiscal year into 52 weeks (occasionally 53), organizing each quarter into two 5-week periods and one 4-week period.
This system is commonly used in retail and financial reporting
Value
ti object
See Also
Other time_intelligence:
atd(),
dod(),
mom(),
momtd(),
mtd(),
mtdopm(),
pqtd(),
pwtd(),
pytd(),
qoq(),
qoqtd(),
qtd(),
qtdopq(),
wow(),
wowtd(),
wtd(),
wtdopw(),
yoy(),
yoytd(),
ytd(),
ytdopy()
Examples
pmtd(contoso::sales,.date=order_date,.value=quantity,calendar_type="standard",lag_n=1)
Previous month-to-date execution function
Description
pmtd_fn() is the function that is called by pmtd() when passed through to calculate
Usage
pmtd_fn(x)
Arguments
x |
ti object |
Details
This is internal non exported function that is nested in ti class and is called upon when the underlying function is called
by calculate
This will return a dbi object that can converted to a tibble object with dplyr::collect()
Value
dbi object
See Also
pmtd() for the function's intent
Prior period quarter-to-date
Description
This calculates the quarterly cumulative sum of targeted value using a standard or 5-5-4 calendar respecting any groups that are passed through with
dplyr::group_by()
use calculate to return the results
Usage
pqtd(
.data,
.date,
.value,
calendar_type = "standard",
lag_n = 1,
fiscal_year_start = 1,
week_start = 7
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by. Must be a Date or POSIXt type. |
.value |
the value column to summarize. Must be numeric. |
calendar_type |
select either 'standard', '445', '454', or '544' calendar, see 'Details' for additional information |
lag_n |
the number of periods to lag |
fiscal_year_start |
integer 1-12, the month the fiscal year starts nearest to (default 1 = January). Only used with the retail calendars ('445', '454', '544'); the standard calendar always uses calendar years, and a message says so if you change it there. |
week_start |
integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday, the default). On the standard calendar it affects only the week functions ( |
Details
This function creates a complete calendar object that fills in any missing days, weeks, months, quarters, or years
If you provide a grouped object with
dplyr::group_by(), it will generate a complete calendar for each groupThe function creates a
tiobject, which pre-processes the data and arguments for further downstream functions
NA Handling
NA values in the
.valuecolumn propagate through cumulative sums (cumsum returns NA once an NA is encountered)NA values in the
.datecolumn are excluded from the calendar join and will not appear in resultsMissing dates (gaps in your data) are filled with 0 values, not NA
standard calendar
The standard calendar splits the year into 12 months (with 28–31 days each) and uses a 7-day week
It automatically accounts for leap years every four years to match the Gregorian calendar
5-5-4 calendar
The 5-5-4 calendar divides the fiscal year into 52 weeks (occasionally 53), organizing each quarter into two 5-week periods and one 4-week period.
This system is commonly used in retail and financial reporting
Value
ti object
See Also
Other time_intelligence:
atd(),
dod(),
mom(),
momtd(),
mtd(),
mtdopm(),
pmtd(),
pwtd(),
pytd(),
qoq(),
qoqtd(),
qtd(),
qtdopq(),
wow(),
wowtd(),
wtd(),
wtdopw(),
yoy(),
yoytd(),
ytd(),
ytdopy()
Examples
pqtd(contoso::sales,.date=order_date,.value=quantity,calendar_type="standard",lag_n=1)
Previous quarter-to-date for tibble objects
Description
pqtd_fn() is the function that is called by pqtd() when passed through to calculate
Usage
pqtd_fn(x)
Arguments
x |
ti object |
Details
This is internal non exported function that is nested in ti class and is called upon when the underlying function is called
by calculate
This will return a dbi object that can converted to a tibble object with dplyr::collect()
Value
dbi object
See Also
pqtd() for the function's intent
Print ti objects
Description
Print ti objects
Print segment objects
Print segment objects
Usage
## S7 method for class <ti::ti>
print(x, ...)
## S7 method for class <ti::segment_abc>
print(x, ...)
## S7 method for class <ti::segment_cohort>
print(x, ...)
Arguments
x |
A |
... |
Unused. Present for S3/S7 compatibility; additional arguments are ignored. |
Value
ti object
segment object
segment object
Print action steps
Description
Print action steps
Usage
print_actions_steps(x)
Arguments
x |
an S7 class |
Value
cli messages
Print the assumptions behind a time intelligence calculation
Description
One line per convention that decides the numbers: what a row is, how periods are compared, how weeks and fiscal years are defined, and how groups are handled. Built only from the object's settings; it runs no query.
Usage
print_assumptions(x)
Arguments
x |
A |
Value
Print calendar information block
Description
Print calendar information block
Usage
print_calendar_info(x)
Arguments
x |
ti or segment obj |
Value
Prints function header info
Description
Prints function header info
Usage
print_fn_info(x)
Arguments
x |
ti or segment obj |
Value
Prints functions next steps
Description
Prints functions next steps
Usage
print_next_steps()
Value
Previous period week-to-date
Description
This calculates the weekly cumulative sum of targeted value for the previous week using a standard or 5-5-4 calendar respecting
any groups that are passed through with dplyr::group_by()
Use calculate to return the results
Usage
pwtd(
.data,
.date,
.value,
calendar_type = "standard",
lag_n = 1,
fiscal_year_start = 1,
week_start = 7
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by. Must be a Date or POSIXt type. |
.value |
the value column to summarize. Must be numeric. |
calendar_type |
select either 'standard', '445', '454', or '544' calendar, see 'Details' for additional information |
lag_n |
the number of periods to lag |
fiscal_year_start |
integer 1-12, the month the fiscal year starts nearest to (default 1 = January). Only used with the retail calendars ('445', '454', '544'); the standard calendar always uses calendar years, and a message says so if you change it there. |
week_start |
integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday, the default). On the standard calendar it affects only the week functions ( |
Details
This function creates a complete calendar object that fills in any missing days, weeks, months, quarters, or years
If you provide a grouped object with
dplyr::group_by(), it will generate a complete calendar for each groupThe function creates a
tiobject, which pre-processes the data and arguments for further downstream functions
NA Handling
NA values in the
.valuecolumn propagate through cumulative sums (cumsum returns NA once an NA is encountered)NA values in the
.datecolumn are excluded from the calendar join and will not appear in resultsMissing dates (gaps in your data) are filled with 0 values, not NA
standard calendar
The standard calendar splits the year into 12 months (with 28–31 days each) and uses a 7-day week
It automatically accounts for leap years every four years to match the Gregorian calendar
5-5-4 calendar
The 5-5-4 calendar divides the fiscal year into 52 weeks (occasionally 53), organizing each quarter into two 5-week periods and one 4-week period.
This system is commonly used in retail and financial reporting
Value
ti object
See Also
Other time_intelligence:
atd(),
dod(),
mom(),
momtd(),
mtd(),
mtdopm(),
pmtd(),
pqtd(),
pytd(),
qoq(),
qoqtd(),
qtd(),
qtdopq(),
wow(),
wowtd(),
wtd(),
wtdopw(),
yoy(),
yoytd(),
ytd(),
ytdopy()
Examples
pwtd(contoso::sales,.date=order_date,.value=quantity,calendar_type="standard",lag_n=1)
Previous week-to-date execution function
Description
pwtd_fn() is the function that is called by pwtd() when passed through to calculate
Usage
pwtd_fn(x)
Arguments
x |
ti object |
Details
This is internal non exported function that is nested in ti class and is called upon when the underlying function is called
by calculate
This will return a dbi object that can converted to a tibble object with dplyr::collect()
Value
dbi object
See Also
pwtd() for the function's intent
Previous period year-to-date
Description
For each group,
pytd()will create the running annual sum of a value based on the calendar type for the previous year compared to the current year calendar dateIf no period exists, it will return
NAThe function returns a ti object which prints out the summary of steps and actions that will take to create the calendar table and calculations
Use calculate to return the results
Usage
pytd(
.data,
.date,
.value,
calendar_type = "standard",
lag_n = 1,
fiscal_year_start = 1,
week_start = 7
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by. Must be a Date or POSIXt type. |
.value |
the value column to summarize. Must be numeric. |
calendar_type |
select either 'standard', '445', '454', or '544' calendar, see 'Details' for additional information |
lag_n |
the number of periods to lag |
fiscal_year_start |
integer 1-12, the month the fiscal year starts nearest to (default 1 = January). Only used with the retail calendars ('445', '454', '544'); the standard calendar always uses calendar years, and a message says so if you change it there. |
week_start |
integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday, the default). On the standard calendar it affects only the week functions ( |
Details
This function creates a complete calendar object that fills in any missing days, weeks, months, quarters, or years
If you provide a grouped object with
dplyr::group_by(), it will generate a complete calendar for each groupThe function creates a
tiobject, which pre-processes the data and arguments for further downstream functions
NA Handling
NA values in the
.valuecolumn propagate through cumulative sums (cumsum returns NA once an NA is encountered)NA values in the
.datecolumn are excluded from the calendar join and will not appear in resultsMissing dates (gaps in your data) are filled with 0 values, not NA
standard calendar
The standard calendar splits the year into 12 months (with 28–31 days each) and uses a 7-day week
It automatically accounts for leap years every four years to match the Gregorian calendar
5-5-4 calendar
The 5-5-4 calendar divides the fiscal year into 52 weeks (occasionally 53), organizing each quarter into two 5-week periods and one 4-week period.
This system is commonly used in retail and financial reporting
Value
ti object
See Also
Other time_intelligence:
atd(),
dod(),
mom(),
momtd(),
mtd(),
mtdopm(),
pmtd(),
pqtd(),
pwtd(),
qoq(),
qoqtd(),
qtd(),
qtdopq(),
wow(),
wowtd(),
wtd(),
wtdopw(),
yoy(),
yoytd(),
ytd(),
ytdopy()
Examples
pytd(contoso::sales,.date=order_date,.value=quantity,calendar_type="standard",lag_n=1)
Previous year-to-date execution function
Description
pytd_fn() is the function that is called by pytd() when passed through to calculate
Usage
pytd_fn(x)
Arguments
x |
ti object |
Details
This is internal non exported function that is nested in ti class and is called upon when the underlying function is called
by calculate
This will return a dbi object that can converted to a tibble object with dplyr::collect()
Value
dbi object
See Also
pytd() for the function's intent
Current full period quarter over previous full period quarter
Description
This calculates the full quarter value compared to the previous quarter value respecting any groups that are passed through with
dplyr::group_by()Use calculate to return the results
Usage
qoq(
.data,
.date,
.value,
calendar_type = "standard",
lag_n = 1,
fiscal_year_start = 1,
week_start = 7
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by. Must be a Date or POSIXt type. |
.value |
the value column to summarize. Must be numeric. |
calendar_type |
select either 'standard', '445', '454', or '544' calendar, see 'Details' for additional information |
lag_n |
the number of periods to lag |
fiscal_year_start |
integer 1-12, the month the fiscal year starts nearest to (default 1 = January). Only used with the retail calendars ('445', '454', '544'); the standard calendar always uses calendar years, and a message says so if you change it there. |
week_start |
integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday, the default). On the standard calendar it affects only the week functions ( |
Value
ti object
See Also
Other time_intelligence:
atd(),
dod(),
mom(),
momtd(),
mtd(),
mtdopm(),
pmtd(),
pqtd(),
pwtd(),
pytd(),
qoqtd(),
qtd(),
qtdopq(),
wow(),
wowtd(),
wtd(),
wtdopw(),
yoy(),
yoytd(),
ytd(),
ytdopy()
Examples
qoq(contoso::sales,.date=order_date,.value=quantity,calendar_type='standard',lag_n=1)
Quarter-over-quarter execution function
Description
qoq_fn() is the function that is called by qoq() when passed through to calculate
Usage
qoq_fn(x)
Arguments
x |
ti object |
Details
This is internal non exported function that is nested in ti class and is called upon when the underlying function is called
by calculate
This will return a dbi object that can converted to a tibble object with dplyr::collect()
Value
dbi object
See Also
qoq() for the function's intent
Current period quarter-to-date compared to previous period quarter-to-date
Description
This calculates the annual cumulative sum of targeted value using a standard or 5-5-4 calendar respecting any groups that are passed through with
dplyr::group_by()Use calculate to return the results
Usage
qoqtd(
.data,
.date,
.value,
calendar_type = "standard",
lag_n = 1,
fiscal_year_start = 1,
week_start = 7
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by. Must be a Date or POSIXt type. |
.value |
the value column to summarize. Must be numeric. |
calendar_type |
select either 'standard', '445', '454', or '544' calendar, see 'Details' for additional information |
lag_n |
the number of periods to lag |
fiscal_year_start |
integer 1-12, the month the fiscal year starts nearest to (default 1 = January). Only used with the retail calendars ('445', '454', '544'); the standard calendar always uses calendar years, and a message says so if you change it there. |
week_start |
integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday, the default). On the standard calendar it affects only the week functions ( |
Details
This function creates a complete calendar object that fills in any missing days, weeks, months, quarters, or years
If you provide a grouped object with
dplyr::group_by(), it will generate a complete calendar for each groupThe function creates a
tiobject, which pre-processes the data and arguments for further downstream functions
NA Handling
NA values in the
.valuecolumn propagate through cumulative sums (cumsum returns NA once an NA is encountered)NA values in the
.datecolumn are excluded from the calendar join and will not appear in resultsMissing dates (gaps in your data) are filled with 0 values, not NA
standard calendar
The standard calendar splits the year into 12 months (with 28–31 days each) and uses a 7-day week
It automatically accounts for leap years every four years to match the Gregorian calendar
5-5-4 calendar
The 5-5-4 calendar divides the fiscal year into 52 weeks (occasionally 53), organizing each quarter into two 5-week periods and one 4-week period.
This system is commonly used in retail and financial reporting
Value
ti object
See Also
Other time_intelligence:
atd(),
dod(),
mom(),
momtd(),
mtd(),
mtdopm(),
pmtd(),
pqtd(),
pwtd(),
pytd(),
qoq(),
qtd(),
qtdopq(),
wow(),
wowtd(),
wtd(),
wtdopw(),
yoy(),
yoytd(),
ytd(),
ytdopy()
Examples
qoqtd(contoso::sales,.date=order_date,.value=quantity,calendar_type="standard",lag_n=1)
Current quarter to date over previous quarter-to-date for tibble objects
Description
qoqtd_fn() is the function that is called by qoqtd() when passed through to calculate
Usage
qoqtd_fn(x)
Arguments
x |
ti object |
Details
This is internal non exported function that is nested in ti class and is called upon when the underlying function is called
by calculate
This will return a dbi object that can converted to a tibble object with dplyr::collect()
Value
dbi object
See Also
qoqtd() for the function's intent
Current period quarter-to-date
Description
This calculates the quarterly cumulative sum of targeted value using a standard or 5-5-4 calendar respecting
any groups that are passed through with dplyr::group_by()
Use calculate to return the results
Usage
qtd(
.data,
.date,
.value,
calendar_type = "standard",
fiscal_year_start = 1,
week_start = 7
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by. Must be a Date or POSIXt type. |
.value |
the value column to summarize. Must be numeric. |
calendar_type |
select either 'standard', '445', '454', or '544' calendar, see 'Details' for additional information |
fiscal_year_start |
integer 1-12, the month the fiscal year starts nearest to (default 1 = January). Only used with the retail calendars ('445', '454', '544'); the standard calendar always uses calendar years, and a message says so if you change it there. |
week_start |
integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday, the default). On the standard calendar it affects only the week functions ( |
Details
This function creates a complete calendar object that fills in any missing days, weeks, months, quarters, or years
If you provide a grouped object with
dplyr::group_by(), it will generate a complete calendar for each groupThe function creates a
tiobject, which pre-processes the data and arguments for further downstream functions
NA Handling
NA values in the
.valuecolumn propagate through cumulative sums (cumsum returns NA once an NA is encountered)NA values in the
.datecolumn are excluded from the calendar join and will not appear in resultsMissing dates (gaps in your data) are filled with 0 values, not NA
standard calendar
The standard calendar splits the year into 12 months (with 28–31 days each) and uses a 7-day week
It automatically accounts for leap years every four years to match the Gregorian calendar
5-5-4 calendar
The 5-5-4 calendar divides the fiscal year into 52 weeks (occasionally 53), organizing each quarter into two 5-week periods and one 4-week period.
This system is commonly used in retail and financial reporting
Value
ti object
See Also
Other time_intelligence:
atd(),
dod(),
mom(),
momtd(),
mtd(),
mtdopm(),
pmtd(),
pqtd(),
pwtd(),
pytd(),
qoq(),
qoqtd(),
qtdopq(),
wow(),
wowtd(),
wtd(),
wtdopw(),
yoy(),
yoytd(),
ytd(),
ytdopy()
Examples
qtd(contoso::sales,.date=order_date,.value=quantity,calendar_type="standard")
Quarter-to-date execution function
Description
qtd_fn() is the function that is called by qtd() when passed through to calculate
Usage
qtd_fn(x)
Arguments
x |
ti object |
Details
This is internal non exported function that is nested in ti class and is called upon when the underlying function is called
by calculate
This will return a dbi object that can converted to a tibble object with dplyr::collect()
Value
dbi object
See Also
qtd() for the function's intent
Current period quarter-to-date over previous period quarter
Description
This calculates the quarterly cumulative sum of a targeted value and compares it with the previous full quarter's total value respecting any groups that are passed through with
dplyr::group_by()Use calculate to return the results
Usage
qtdopq(
.data,
.date,
.value,
calendar_type = "standard",
lag_n = 1,
fiscal_year_start = 1,
week_start = 7
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by. Must be a Date or POSIXt type. |
.value |
the value column to summarize. Must be numeric. |
calendar_type |
select either 'standard', '445', '454', or '544' calendar, see 'Details' for additional information |
lag_n |
the number of periods to lag |
fiscal_year_start |
integer 1-12, the month the fiscal year starts nearest to (default 1 = January). Only used with the retail calendars ('445', '454', '544'); the standard calendar always uses calendar years, and a message says so if you change it there. |
week_start |
integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday, the default). On the standard calendar it affects only the week functions ( |
Details
This function creates a complete calendar object that fills in any missing days, weeks, months, quarters, or years
If you provide a grouped object with
dplyr::group_by(), it will generate a complete calendar for each groupThe function creates a
tiobject, which pre-processes the data and arguments for further downstream functions
NA Handling
NA values in the
.valuecolumn propagate through cumulative sums (cumsum returns NA once an NA is encountered)NA values in the
.datecolumn are excluded from the calendar join and will not appear in resultsMissing dates (gaps in your data) are filled with 0 values, not NA
standard calendar
The standard calendar splits the year into 12 months (with 28–31 days each) and uses a 7-day week
It automatically accounts for leap years every four years to match the Gregorian calendar
5-5-4 calendar
The 5-5-4 calendar divides the fiscal year into 52 weeks (occasionally 53), organizing each quarter into two 5-week periods and one 4-week period.
This system is commonly used in retail and financial reporting
Value
ti object
See Also
Other time_intelligence:
atd(),
dod(),
mom(),
momtd(),
mtd(),
mtdopm(),
pmtd(),
pqtd(),
pwtd(),
pytd(),
qoq(),
qoqtd(),
qtd(),
wow(),
wowtd(),
wtd(),
wtdopw(),
yoy(),
yoytd(),
ytd(),
ytdopy()
Examples
qtdopq(contoso::sales,.date=order_date,.value=quantity,calendar_type='standard',lag_n=1)
quarter-to-date over previous quarter execution function
Description
qtdopq_fn() is the function that is called by qtdopq() when passed through to calculate
Usage
qtdopq_fn(x)
Arguments
x |
ti object |
Details
This is internal non exported function that is nested in ti class and is called upon when the underlying function is called
by calculate
This will return a dbi object that can converted to a tibble object with dplyr::collect()
Value
dbi object
See Also
qtdopq() for the function's intent
ABC segmentation class
Description
segment_abc is the lazy object returned by abc(). It mirrors ti but
swaps the time-shift metadata for a category object holding the
bucket cut-points. Pass it to calculate() to run the segmentation.
Usage
segment_abc(
datum = datum(),
category = category(),
time_unit = time_unit(),
fn = fn(),
action = action(),
value = value()
)
Arguments
datum |
A datum object holding the table and its date metadata. |
category |
A category object giving the bucket cut-points. |
time_unit |
A time_unit object giving the granularity. |
fn |
An fn object holding the transformation to execute. |
action |
An action object describing the calculation for printing. |
value |
A value object naming the measure and output column. |
Value
A segment_abc S7 object.
Cohort segmentation class
Description
segment_cohort is the lazy object returned by cohort(). It groups records
by the period in which each group member first appears, then measures each
cohort forward through time. Pass it to calculate() to run the
segmentation.
Usage
segment_cohort(
datum = datum(),
time_unit = time_unit(),
fn = fn(),
action = action(),
value = value()
)
Arguments
datum |
A datum object holding the table and its date metadata. |
time_unit |
A time_unit object giving the cohort period. |
fn |
An fn object holding the transformation to execute. |
action |
An action object describing the calculation for printing. |
value |
A value object naming the measure and output column. |
Value
A segment_cohort S7 object.
Generate a Cross-Dialect SQL Date Series
Description
Creates a lazy dbplyr table containing a continuous sequence of dates.
The function automatically detects the SQL dialect of the connection and
dispatches the most efficient native series generator (e.g., GENERATE_SERIES
for DuckDB/Postgres or GENERATOR for Snowflake).
Usage
seq_date_sql(
.con,
start_date,
end_date,
calendar_type = "standard",
time_unit = "day",
week_start = 7,
fiscal_year_start = 1
)
Arguments
.con |
A valid DBI connection object (e.g., DuckDB, Postgres, Snowflake)
or a |
start_date |
A character string in 'YYYY-MM-DD' format or a Date object representing the start of the series. |
end_date |
A character string in 'YYYY-MM-DD' format or a Date object representing the end of the series. |
calendar_type |
One of "standard", "445", "454" or "544". |
time_unit |
A character string specifying the interval. Must be one of:
|
week_start |
Integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday). |
fiscal_year_start |
Integer 1-12, month the fiscal year starts nearest to (retail calendars only). |
Details
This function is designed to be "nestable," meaning the resulting SQL can be
used safely inside larger dplyr pipelines. It avoids WITH clauses in
dialects like DuckDB to prevent parser errors when dbplyr wraps the query
in a subquery (e.g., SELECT * FROM (...) AS q01).
For unit testing, the function supports dbplyr simulation objects. If a
TestConnection is detected, it returns a lazy_frame to avoid metadata
field queries that would otherwise fail on a mock connection.
Value
A tbl_lazy (SQL) object with one row per period: date
(the period's first day) and the calendar label columns for time_unit.
Generate dialect-appropriate date addition SQL
Description
Generate dialect-appropriate date addition SQL
Usage
sql_date_add(.con, unit, n_expr, date_col = "date")
Arguments
.con |
A DBI connection object |
unit |
A character string: "month", "week", etc. |
n_expr |
An expression string for the number of units |
date_col |
A character string for the date column name |
Value
A dplyr::sql object
Same point in time in an earlier period
Description
SQL for the cutoff date used by the previous-period-to-date functions:
date moved back lag_n weeks, months, quarters or years. Moving back by
months clamps to the end of a shorter month (31 May minus 3 months is
29 February), and when date is the last day of its month the cutoff is the
last day of the earlier month, so 28 February 2025 compares with the whole of
February 2024 and 30 April with the whole of January.
Usage
sql_period_cutoff(.con, unit, lag_n)
Arguments
.con |
A DBI connection |
unit |
One of "week", "month", "quarter" or "year" |
lag_n |
Number of periods to move back |
Value
A SQL expression on the date column
Time-intelligence class
Description
ti is the object returned by every time-intelligence function (ytd(),
yoy(), mtd() and so on). It composes the data (datum), the
granularity (time_unit), the measure (value), the
calculation blueprint (fn) and the print narrative (action)
into a single lazy object. Nothing is computed until it is passed to
calculate().
Usage
ti(
datum = datum(),
time_unit = time_unit(),
value = value(),
fn = fn(),
action = action()
)
Arguments
datum |
A datum object holding the table and its date metadata. |
time_unit |
A time_unit object giving the granularity. |
value |
A value object naming the measure and output column. |
fn |
An fn object holding the transformation to execute. |
action |
An action object describing the calculation for printing. |
Value
A ti S7 object.
Time unit class
Description
time_unit records the calendar granularity that a date column is floored to
before a time-intelligence calculation is run. The value is lower-cased on
assignment and must be one of "day", "week", "month", "quarter" or
"year".
Usage
time_unit(value = "day")
Arguments
value |
A single string giving the time unit. |
Value
A time_unit S7 object.
Value class
Description
value records which column is being measured and what the resulting column
should be called. Assigning new_column_name_vec prefixes the supplied
string onto value_vec, so setting it to "ytd" for a value column of
sales gives ytd_sales.
Usage
value(value_vec = NA_character_, new_column_name_vec = character(0))
Arguments
value_vec |
The name of the value column, as a string. |
new_column_name_vec |
A prefix for the output column; stored as
|
Value
A value S7 object.
Additional properties
@value_quovalue_vecparsed to a symbol for tidy evaluation.@new_column_name_quonew_column_name_vecparsed to a symbol.
Current full period week over full previous period week
Description
This calculates the full week value compared to the previous week value using a standard or 5-5-4 calendar respecting
any groups that are passed through with dplyr::group_by()
Use calculate to return the results
Usage
wow(
.data,
.date,
.value,
calendar_type = "standard",
lag_n = 1,
fiscal_year_start = 1,
week_start = 7
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by. Must be a Date or POSIXt type. |
.value |
the value column to summarize. Must be numeric. |
calendar_type |
select either 'standard', '445', '454', or '544' calendar, see 'Details' for additional information |
lag_n |
the number of periods to lag |
fiscal_year_start |
integer 1-12, the month the fiscal year starts nearest to (default 1 = January). Only used with the retail calendars ('445', '454', '544'); the standard calendar always uses calendar years, and a message says so if you change it there. |
week_start |
integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday, the default). On the standard calendar it affects only the week functions ( |
Details
This function creates a complete calendar object that fills in any missing days, weeks, months, quarters, or years
If you provide a grouped object with
dplyr::group_by(), it will generate a complete calendar for each groupThe function creates a
tiobject, which pre-processes the data and arguments for further downstream functions
NA Handling
NA values in the
.valuecolumn propagate through cumulative sums (cumsum returns NA once an NA is encountered)NA values in the
.datecolumn are excluded from the calendar join and will not appear in resultsMissing dates (gaps in your data) are filled with 0 values, not NA
standard calendar
The standard calendar splits the year into 12 months (with 28–31 days each) and uses a 7-day week
It automatically accounts for leap years every four years to match the Gregorian calendar
5-5-4 calendar
The 5-5-4 calendar divides the fiscal year into 52 weeks (occasionally 53), organizing each quarter into two 5-week periods and one 4-week period.
This system is commonly used in retail and financial reporting
Value
ti object
See Also
Other time_intelligence:
atd(),
dod(),
mom(),
momtd(),
mtd(),
mtdopm(),
pmtd(),
pqtd(),
pwtd(),
pytd(),
qoq(),
qoqtd(),
qtd(),
qtdopq(),
wowtd(),
wtd(),
wtdopw(),
yoy(),
yoytd(),
ytd(),
ytdopy()
Examples
wow(contoso::sales,.date=order_date,.value=quantity,calendar_type='standard',lag_n=1)
Week-over-week execution function
Description
wow_fn() is the function that is called by wow() when passed through to calculate
Usage
wow_fn(x)
Arguments
x |
ti object |
Details
This is internal non exported function that is nested in ti class and is called upon when the underlying function is called
by calculate
This will return a dbi object that can converted to a tibble object with dplyr::collect()
Value
dbi object
See Also
wow() for the function's intent
Current period Week-to-date over previous period week-to-date
Description
This calculates the weekly cumulative sum of targeted value and compares it with the previous week's cumulative sum using a standard or 5-5-4 calendar respecting
any groups that are passed through with dplyr::group_by()
Use calculate to return the results
Usage
wowtd(
.data,
.date,
.value,
calendar_type = "standard",
lag_n = 1,
fiscal_year_start = 1,
week_start = 7
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by. Must be a Date or POSIXt type. |
.value |
the value column to summarize. Must be numeric. |
calendar_type |
select either 'standard', '445', '454', or '544' calendar, see 'Details' for additional information |
lag_n |
the number of periods to lag |
fiscal_year_start |
integer 1-12, the month the fiscal year starts nearest to (default 1 = January). Only used with the retail calendars ('445', '454', '544'); the standard calendar always uses calendar years, and a message says so if you change it there. |
week_start |
integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday, the default). On the standard calendar it affects only the week functions ( |
Details
This function creates a complete calendar object that fills in any missing days, weeks, months, quarters, or years
If you provide a grouped object with
dplyr::group_by(), it will generate a complete calendar for each groupThe function creates a
tiobject, which pre-processes the data and arguments for further downstream functions
NA Handling
NA values in the
.valuecolumn propagate through cumulative sums (cumsum returns NA once an NA is encountered)NA values in the
.datecolumn are excluded from the calendar join and will not appear in resultsMissing dates (gaps in your data) are filled with 0 values, not NA
standard calendar
The standard calendar splits the year into 12 months (with 28–31 days each) and uses a 7-day week
It automatically accounts for leap years every four years to match the Gregorian calendar
5-5-4 calendar
The 5-5-4 calendar divides the fiscal year into 52 weeks (occasionally 53), organizing each quarter into two 5-week periods and one 4-week period.
This system is commonly used in retail and financial reporting
Value
ti object
See Also
Other time_intelligence:
atd(),
dod(),
mom(),
momtd(),
mtd(),
mtdopm(),
pmtd(),
pqtd(),
pwtd(),
pytd(),
qoq(),
qoqtd(),
qtd(),
qtdopq(),
wow(),
wtd(),
wtdopw(),
yoy(),
yoytd(),
ytd(),
ytdopy()
Examples
wowtd(contoso::sales,.date=order_date,.value=quantity,calendar_type="standard",lag_n=1)
Week-to-date over previous week-to-date execution function
Description
wowtd_fn() is the function that is called by wowtd() when passed through to calculate
Usage
wowtd_fn(x)
Arguments
x |
ti object |
Details
This is internal non exported function that is nested in ti class and is called upon when the underlying function is called
by calculate
This will return a dbi object that can converted to a tibble object with dplyr::collect()
Value
dbi object
See Also
wowtd() for the function's intent
Current period week-to-date
Description
This calculates the weekly cumulative sum of targeted value using a standard or 5-5-4 calendar respecting
any groups that are passed through with dplyr::group_by()
Use calculate to return the results
Usage
wtd(
.data,
.date,
.value,
calendar_type = "standard",
fiscal_year_start = 1,
week_start = 7
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by. Must be a Date or POSIXt type. |
.value |
the value column to summarize. Must be numeric. |
calendar_type |
select either 'standard', '445', '454', or '544' calendar, see 'Details' for additional information |
fiscal_year_start |
integer 1-12, the month the fiscal year starts nearest to (default 1 = January). Only used with the retail calendars ('445', '454', '544'); the standard calendar always uses calendar years, and a message says so if you change it there. |
week_start |
integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday, the default). On the standard calendar it affects only the week functions ( |
Details
This function creates a complete calendar object that fills in any missing days, weeks, months, quarters, or years
If you provide a grouped object with
dplyr::group_by(), it will generate a complete calendar for each groupThe function creates a
tiobject, which pre-processes the data and arguments for further downstream functions
NA Handling
NA values in the
.valuecolumn propagate through cumulative sums (cumsum returns NA once an NA is encountered)NA values in the
.datecolumn are excluded from the calendar join and will not appear in resultsMissing dates (gaps in your data) are filled with 0 values, not NA
standard calendar
The standard calendar splits the year into 12 months (with 28–31 days each) and uses a 7-day week
It automatically accounts for leap years every four years to match the Gregorian calendar
5-5-4 calendar
The 5-5-4 calendar divides the fiscal year into 52 weeks (occasionally 53), organizing each quarter into two 5-week periods and one 4-week period.
This system is commonly used in retail and financial reporting
Value
ti object
See Also
Other time_intelligence:
atd(),
dod(),
mom(),
momtd(),
mtd(),
mtdopm(),
pmtd(),
pqtd(),
pwtd(),
pytd(),
qoq(),
qoqtd(),
qtd(),
qtdopq(),
wow(),
wowtd(),
wtdopw(),
yoy(),
yoytd(),
ytd(),
ytdopy()
Examples
wtd(contoso::sales,.date=order_date,.value=quantity,calendar_type="standard")
Week-to-date execution function
Description
wtd_fn() is the function that is called by wtd() when passed through to calculate
Usage
wtd_fn(x)
Arguments
x |
ti object |
Details
This is internal non exported function that is nested in ti class and is called upon when the underlying function is called
by calculate
This will return a dbi object that can converted to a tibble object with dplyr::collect()
Value
dbi object
See Also
wtd() for the function's intent
Current period week-to-date over full previous period week
Description
This calculates the weekly cumulative sum of targeted value and compares it with the full previous week's total using a standard or 5-5-4 calendar respecting
any groups that are passed through with dplyr::group_by()
Use calculate to return the results
Usage
wtdopw(
.data,
.date,
.value,
calendar_type = "standard",
lag_n = 1,
fiscal_year_start = 1,
week_start = 7
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by. Must be a Date or POSIXt type. |
.value |
the value column to summarize. Must be numeric. |
calendar_type |
select either 'standard', '445', '454', or '544' calendar, see 'Details' for additional information |
lag_n |
the number of periods to lag |
fiscal_year_start |
integer 1-12, the month the fiscal year starts nearest to (default 1 = January). Only used with the retail calendars ('445', '454', '544'); the standard calendar always uses calendar years, and a message says so if you change it there. |
week_start |
integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday, the default). On the standard calendar it affects only the week functions ( |
Details
This function creates a complete calendar object that fills in any missing days, weeks, months, quarters, or years
If you provide a grouped object with
dplyr::group_by(), it will generate a complete calendar for each groupThe function creates a
tiobject, which pre-processes the data and arguments for further downstream functions
NA Handling
NA values in the
.valuecolumn propagate through cumulative sums (cumsum returns NA once an NA is encountered)NA values in the
.datecolumn are excluded from the calendar join and will not appear in resultsMissing dates (gaps in your data) are filled with 0 values, not NA
standard calendar
The standard calendar splits the year into 12 months (with 28–31 days each) and uses a 7-day week
It automatically accounts for leap years every four years to match the Gregorian calendar
5-5-4 calendar
The 5-5-4 calendar divides the fiscal year into 52 weeks (occasionally 53), organizing each quarter into two 5-week periods and one 4-week period.
This system is commonly used in retail and financial reporting
Value
ti object
See Also
Other time_intelligence:
atd(),
dod(),
mom(),
momtd(),
mtd(),
mtdopm(),
pmtd(),
pqtd(),
pwtd(),
pytd(),
qoq(),
qoqtd(),
qtd(),
qtdopq(),
wow(),
wowtd(),
wtd(),
yoy(),
yoytd(),
ytd(),
ytdopy()
Examples
wtdopw(contoso::sales,.date=order_date,.value=quantity,calendar_type="standard",lag_n=1)
Week-to-date over full previous week execution function
Description
wtdopw_fn() is the function that is called by wtdopw() when passed through to calculate
Usage
wtdopw_fn(x)
Arguments
x |
ti object |
Details
This is internal non exported function that is nested in ti class and is called upon when the underlying function is called
by calculate
This will return a dbi object that can converted to a tibble object with dplyr::collect()
Value
dbi object
See Also
wtdopw() for the function's intent
Current full period year over previous full period year
Description
This calculates the full year value compared to the previous year value respecting any groups that are passed through with
dplyr::group_by()Use calculate to return the results
Usage
yoy(
.data,
.date,
.value,
calendar_type = "standard",
lag_n = 1,
fiscal_year_start = 1,
week_start = 7
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by. Must be a Date or POSIXt type. |
.value |
the value column to summarize. Must be numeric. |
calendar_type |
select either 'standard', '445', '454', or '544' calendar, see 'Details' for additional information |
lag_n |
the number of periods to lag |
fiscal_year_start |
integer 1-12, the month the fiscal year starts nearest to (default 1 = January). Only used with the retail calendars ('445', '454', '544'); the standard calendar always uses calendar years, and a message says so if you change it there. |
week_start |
integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday, the default). On the standard calendar it affects only the week functions ( |
Details
This function creates a complete calendar object that fills in any missing days, weeks, months, quarters, or years
If you provide a grouped object with
dplyr::group_by(), it will generate a complete calendar for each groupThe function creates a
tiobject, which pre-processes the data and arguments for further downstream functions
NA Handling
NA values in the
.valuecolumn propagate through cumulative sums (cumsum returns NA once an NA is encountered)NA values in the
.datecolumn are excluded from the calendar join and will not appear in resultsMissing dates (gaps in your data) are filled with 0 values, not NA
standard calendar
The standard calendar splits the year into 12 months (with 28–31 days each) and uses a 7-day week
It automatically accounts for leap years every four years to match the Gregorian calendar
5-5-4 calendar
The 5-5-4 calendar divides the fiscal year into 52 weeks (occasionally 53), organizing each quarter into two 5-week periods and one 4-week period.
This system is commonly used in retail and financial reporting
Value
ti object
See Also
Other time_intelligence:
atd(),
dod(),
mom(),
momtd(),
mtd(),
mtdopm(),
pmtd(),
pqtd(),
pwtd(),
pytd(),
qoq(),
qoqtd(),
qtd(),
qtdopq(),
wow(),
wowtd(),
wtd(),
wtdopw(),
yoytd(),
ytd(),
ytdopy()
Examples
yoy(contoso::sales,.date=order_date,.value=quantity,calendar_type='standard',lag_n=1)
Current year-to-date over previous period year-to-date execution function
Description
yoy_fn() is the function that is called by yoy() when passed through to calculate
Usage
yoy_fn(x)
Arguments
x |
ti object |
Details
This is internal non exported function that is nested in ti class and is called upon when the underlying function is called
by calculate
This will return a dbi object that can converted to a tibble object with dplyr::collect()
Value
dbi object
See Also
yoy() for the function's intent
Current period year-to-date compared to previous period year-to-date
Description
This calculates the annual cumulative sum of targeted value and compares it with the previous period's annual cumulative to date sum using a standard or 5-5-4 calendar respecting any groups that are passed through with
dplyr::group_by()Use calculate to return the results
Usage
yoytd(
.data,
.date,
.value,
calendar_type = "standard",
lag_n = 1,
fiscal_year_start = 1,
week_start = 7
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by. Must be a Date or POSIXt type. |
.value |
the value column to summarize. Must be numeric. |
calendar_type |
select either 'standard', '445', '454', or '544' calendar, see 'Details' for additional information |
lag_n |
the number of periods to lag |
fiscal_year_start |
integer 1-12, the month the fiscal year starts nearest to (default 1 = January). Only used with the retail calendars ('445', '454', '544'); the standard calendar always uses calendar years, and a message says so if you change it there. |
week_start |
integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday, the default). On the standard calendar it affects only the week functions ( |
Details
This function creates a complete calendar object that fills in any missing days, weeks, months, quarters, or years
If you provide a grouped object with
dplyr::group_by(), it will generate a complete calendar for each groupThe function creates a
tiobject, which pre-processes the data and arguments for further downstream functions
NA Handling
NA values in the
.valuecolumn propagate through cumulative sums (cumsum returns NA once an NA is encountered)NA values in the
.datecolumn are excluded from the calendar join and will not appear in resultsMissing dates (gaps in your data) are filled with 0 values, not NA
standard calendar
The standard calendar splits the year into 12 months (with 28–31 days each) and uses a 7-day week
It automatically accounts for leap years every four years to match the Gregorian calendar
5-5-4 calendar
The 5-5-4 calendar divides the fiscal year into 52 weeks (occasionally 53), organizing each quarter into two 5-week periods and one 4-week period.
This system is commonly used in retail and financial reporting
Value
ti object
See Also
Other time_intelligence:
atd(),
dod(),
mom(),
momtd(),
mtd(),
mtdopm(),
pmtd(),
pqtd(),
pwtd(),
pytd(),
qoq(),
qoqtd(),
qtd(),
qtdopq(),
wow(),
wowtd(),
wtd(),
wtdopw(),
yoy(),
ytd(),
ytdopy()
Examples
yoytd(contoso::sales,.date=order_date,.value=quantity,calendar_type="standard",lag_n=1)
Current year to date over previous year-to-date execution function
Description
yoytd_fn() is the function that is called by yoytd() when passed through to calculate
Usage
yoytd_fn(x)
Arguments
x |
ti object |
Details
This is internal non exported function that is nested in ti class and is called upon when the underlying function is called
by calculate
This will return a dbi object that can converted to a tibble object with dplyr::collect()
Value
dbi object
See Also
yoytd() for the function's intent
Current period year-to-date
Description
For each group,
ytd()will create the running annual sum of a value based on the calendar type specifiedThe function returns a ti object which prints out the summary of steps and actions that will take to create the calendar table and calculations
Use calculate to return the results
Usage
ytd(
.data,
.date,
.value,
calendar_type = "standard",
fiscal_year_start = 1,
week_start = 7
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by. Must be a Date or POSIXt type. |
.value |
the value column to summarize. Must be numeric. |
calendar_type |
select either 'standard', '445', '454', or '544' calendar, see 'Details' for additional information |
fiscal_year_start |
integer 1-12, the month the fiscal year starts nearest to (default 1 = January). Only used with the retail calendars ('445', '454', '544'); the standard calendar always uses calendar years, and a message says so if you change it there. |
week_start |
integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday, the default). On the standard calendar it affects only the week functions ( |
Details
This function creates a complete calendar object that fills in any missing days, weeks, months, quarters, or years
If you provide a grouped object with
dplyr::group_by(), it will generate a complete calendar for each groupThe function creates a
tiobject, which pre-processes the data and arguments for further downstream functions
NA Handling
NA values in the
.valuecolumn propagate through cumulative sums (cumsum returns NA once an NA is encountered)NA values in the
.datecolumn are excluded from the calendar join and will not appear in resultsMissing dates (gaps in your data) are filled with 0 values, not NA
standard calendar
The standard calendar splits the year into 12 months (with 28–31 days each) and uses a 7-day week
It automatically accounts for leap years every four years to match the Gregorian calendar
5-5-4 calendar
The 5-5-4 calendar divides the fiscal year into 52 weeks (occasionally 53), organizing each quarter into two 5-week periods and one 4-week period.
This system is commonly used in retail and financial reporting
Value
ti object
See Also
Other time_intelligence:
atd(),
dod(),
mom(),
momtd(),
mtd(),
mtdopm(),
pmtd(),
pqtd(),
pwtd(),
pytd(),
qoq(),
qoqtd(),
qtd(),
qtdopq(),
wow(),
wowtd(),
wtd(),
wtdopw(),
yoy(),
yoytd(),
ytdopy()
Examples
ytd(contoso::sales,.date=order_date,.value=quantity,calendar_type="standard")
Year-to-date execution function
Description
ytd_fn() is the function that is called by ytd() when passed through to calculate
Usage
ytd_fn(x)
Arguments
x |
ti object |
Details
This is internal non exported function that is nested in ti class and is called upon when the underlying function is called
by calculate
This will return a dbi object that can converted to a tibble object with dplyr::collect()
Value
dbi object
See Also
ytd() for the function's class
Current period year-to-date compared to full previous period
Description
This calculates the full year value compared to the previous year value using a standard or 5-5-4 calendar respecting any groups that are passed through with
dplyr::group_by()Use calculate to return the results
Usage
ytdopy(
.data,
.date,
.value,
calendar_type = "standard",
lag_n = 1,
fiscal_year_start = 1,
week_start = 7
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by. Must be a Date or POSIXt type. |
.value |
the value column to summarize. Must be numeric. |
calendar_type |
select either 'standard', '445', '454', or '544' calendar, see 'Details' for additional information |
lag_n |
the number of periods to lag |
fiscal_year_start |
integer 1-12, the month the fiscal year starts nearest to (default 1 = January). Only used with the retail calendars ('445', '454', '544'); the standard calendar always uses calendar years, and a message says so if you change it there. |
week_start |
integer 1-7, the day weeks start on (1 = Monday, 7 = Sunday, the default). On the standard calendar it affects only the week functions ( |
Details
This function creates a complete calendar object that fills in any missing days, weeks, months, quarters, or years
If you provide a grouped object with
dplyr::group_by(), it will generate a complete calendar for each groupThe function creates a
tiobject, which pre-processes the data and arguments for further downstream functions
NA Handling
NA values in the
.valuecolumn propagate through cumulative sums (cumsum returns NA once an NA is encountered)NA values in the
.datecolumn are excluded from the calendar join and will not appear in resultsMissing dates (gaps in your data) are filled with 0 values, not NA
standard calendar
The standard calendar splits the year into 12 months (with 28–31 days each) and uses a 7-day week
It automatically accounts for leap years every four years to match the Gregorian calendar
5-5-4 calendar
The 5-5-4 calendar divides the fiscal year into 52 weeks (occasionally 53), organizing each quarter into two 5-week periods and one 4-week period.
This system is commonly used in retail and financial reporting
Value
ti object
See Also
Other time_intelligence:
atd(),
dod(),
mom(),
momtd(),
mtd(),
mtdopm(),
pmtd(),
pqtd(),
pwtd(),
pytd(),
qoq(),
qoqtd(),
qtd(),
qtdopq(),
wow(),
wowtd(),
wtd(),
wtdopw(),
yoy(),
yoytd(),
ytd()
Examples
ytdopy(contoso::sales,.date=order_date,.value=quantity,calendar_type='standard',lag_n=1)
Year-to-date over full prior period year
Description
ytdopy_fn() is the function that is called by ytdopy() when passed through to calculate
Usage
ytdopy_fn(x)
Arguments
x |
ti object |
Details
This is internal non exported function that is nested in ti class and is called upon when the underlying function is called
by calculate
This will return a dbi object that can converted to a tibble object withdplyr::collect()
Value
dbi object
See Also
ytdopy() for the function's intent