| 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.0.0 |
| License: | MIT + file LICENSE |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| Imports: | assertthat, cli, DBI, dbplyr, dplyr, duckdb, glue, janitor, lubridate, rlang, S7, scales, tidyr |
| Suggests: | testthat (≥ 3.0.0), cohorts, quarto, devtools, tibble, gt, fansi, crayon, contoso |
| Config/testthat/edition: | 3 |
| Depends: | R (≥ 4.2.0) |
| URL: | https://codeberg.org/usrbinr/ti |
| Repository: | CRAN |
| NeedsCompilation: | no |
| Packaged: | 2026-02-07 05:22:48 UTC; hagan |
| Author: | Alejandro Hagan [aut, cre] |
| Maintainer: | Alejandro Hagan <alejandro.hagan@outlook.com> |
| Date/Publication: | 2026-02-10 20:30: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 = 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
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)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by |
.value |
the value column to summarize |
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 retail calendars ('445', '454', '544'). |
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
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.
Arguments
x |
ti object |
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 remote database backend (like duckdb or snowflake).
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)
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 and tested with Snowflake and DuckDB.
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
Arguments
x |
ti object |
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
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
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by |
.value |
the value column to summarize |
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 retail calendars ('445', '454', '544'). |
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
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
Generate CLI actions
Description
Generate CLI actions
Usage
generate_cli_action(x, word)
Arguments
x |
input to test against |
word |
the key word to validate |
Value
list
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
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
Make Action field CLI args
Description
Make Action field CLI args
Usage
make_action_cli(x)
Arguments
x |
action class |
Value
list
Make an in memory database from a 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
dbi object
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
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by |
.value |
the value column to summarize |
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 retail calendars ('445', '454', '544'). |
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
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
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by |
.value |
the value column to summarize |
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 retail calendars ('445', '454', '544'). |
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
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)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by |
.value |
the value column to summarize |
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 retail calendars ('445', '454', '544'). |
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
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
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by |
.value |
the value column to summarize |
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 retail calendars ('445', '454', '544'). |
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
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
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
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by |
.value |
the value column to summarize |
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 retail calendars ('445', '454', '544'). |
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
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
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by |
.value |
the value column to summarize |
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 retail calendars ('445', '454', '544'). |
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
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
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 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
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by |
.value |
the value column to summarize |
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 retail calendars ('445', '454', '544'). |
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
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,
fiscal_year_start = 1
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by |
.value |
the value column to summarize |
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 retail calendars ('445', '454', '544'). |
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
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
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by |
.value |
the value column to summarize |
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 retail calendars ('445', '454', '544'). |
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
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by |
.value |
the value column to summarize |
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 retail calendars ('445', '454', '544'). |
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
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)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by |
.value |
the value column to summarize |
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 retail calendars ('445', '454', '544'). |
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
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
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by |
.value |
the value column to summarize |
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 retail calendars ('445', '454', '544'). |
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
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
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. |
time_unit |
A character string specifying the interval. Must be one of:
|
week_start |
description |
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 a single column date.
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
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
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by |
.value |
the value column to summarize |
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 retail calendars ('445', '454', '544'). |
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
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
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by |
.value |
the value column to summarize |
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 retail calendars ('445', '454', '544'). |
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
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)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by |
.value |
the value column to summarize |
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 retail calendars ('445', '454', '544'). |
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
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
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by |
.value |
the value column to summarize |
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 retail calendars ('445', '454', '544'). |
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
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
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by |
.value |
the value column to summarize |
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 retail calendars ('445', '454', '544'). |
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
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,
fiscal_year_start = 1
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by |
.value |
the value column to summarize |
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 retail calendars ('445', '454', '544'). |
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
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)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by |
.value |
the value column to summarize |
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 retail calendars ('445', '454', '544'). |
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
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
)
Arguments
.data |
tibble or dbi object (either grouped or ungrouped) |
.date |
the date column to group by |
.value |
the value column to summarize |
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 retail calendars ('445', '454', '544'). |
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
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