You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: vignettes/articles/getting_started_with_ti.qmd
+31-42Lines changed: 31 additions & 42 deletions
Original file line number
Diff line number
Diff line change
@@ -13,32 +13,31 @@ format: html
13
13
library(dplyr)
14
14
library(fpaR)
15
15
16
-
17
16
hook <- fansi::set_knit_hooks(knitr::knit_hooks, which = c("output", "warning", "error", "message"))
18
17
19
18
options(crayon.enabled = TRUE)
20
19
20
+
21
21
```
22
22
23
23
24
24
## How to use fpaR?
25
25
26
-
### Time Intelligence
27
-
28
-
When you execute a time intelligence function, it will return a "ti" class object with a custom print method that explains what the function is doing and a summary of transformation steps and the calendar attributes.
29
-
30
26
Simply pass your data in either tibble or a lazy DBI object to the time intelligence function and input the required arguments.
31
27
32
28
> Regardless if you pass a tibble or lazy DBI object, all time intelligence functions will return a lazy DBI object for performance reasons
33
29
34
-
We will use `mtd()` function to calculate the month-to-date sum of contoso's company' revenue (`contoso::sales`).
30
+
We will use `mtd()` function to calculate the month-to-date sum of contoso's company' margin (`contoso::sales`).
35
31
36
32
Most time intelligence functions follow the same structure:
37
33
38
-
- specify the date column to index the time intelligence functions
39
-
- specify the value column to aggregate
40
-
- if there is a period rollback / rollforward then clarify the number of periods
41
-
- clarify if we are using a "standard" calendar or non-standard variation (currently supports 5-5-4)
34
+
- Specify the date column to index the time intelligence functions (eg. `order_date` or `deliver_date`)
35
+
- Specify the value column to aggregate
36
+
- If there is a period rollback / rollforward then clarify the number of periods to roll
37
+
- Clarify if we are using a "standard" calendar or non-standard variation (currently supports 5-4-4, 4-4-5 and 4-5-4 calendars) see [standard vs. non standard calendar article](https://usrbinr.github.io/fpaR/articles/calendar_types.html)
38
+
39
+
> For most of your uses cases, you are likely to reference "standard" calendar which is your standard gregorian calendar:
40
+
> - 365 days in a year except for leap years where you have 366, 7 days make up a week, January has 30 days, etc
42
41
43
42
When you execute `mtd()`, your console return a `ti` object and will print a summary of the function's actions, details the calendar's attributes, describes the main transformation steps and lists out possible next actions.
44
43
@@ -49,7 +48,7 @@ When you execute `mtd()`, your console return a `ti` object and will print a su
The functions will work with your database even if you don't have write permission by creatively leveraging CTEs to create interim tables.
111
+
In the print, we
116
112
117
-
## Why do we need this package when we have lubridate?
113
+
###Why do we need this package when we have lubridate?
118
114
119
-
[Lubridate](https://lubridate.tidyverse.org/) is an excellent package and is heavily used by the package. The issue isn't lubridate but rather
120
-
issues you may not be aware of in your package.
115
+
[Lubridate](https://lubridate.tidyverse.org/) is an excellent package and is heavily used by the package. The issue isn't lubridate but rather challenges and issues in your dataset that aren't readily visible.
121
116
122
-
Time-based comparisons, such as Year-over-Year (YoY), Quarter-over-Quarter (QoQ), and Month-to-Date (MTD), are common for tracking business performance. However, they come with challenges:
123
117
124
118
- Many datasets **do not have continuous dates**, especially if data is recorded only on business days or for active transactions
125
119
126
-
- Period imbalances between periods (Eg. the different number of days between February vs. January) can create misleading analysis or trends
127
120
128
-
- Your analysis may need to reference a non-standard calendar such as a 5-5-4, 4-4-5, or 13 month calendar
121
+
- Period imbalances between periods (Eg. the different number of days between February vs. January) can create misleading analysis or trends requiring non-standard calendars (eg. 4-4-5)
122
+
123
+
- Calculating time intelligence for groups can lead to larger than memory issues even with smaller datasets
129
124
130
-
- Your data may be in excel sheets, csv or databases and you need to inter-operable framework to switch between all your data types
131
125
132
126
### Issue 1: Continuous Dates
133
127
@@ -171,15 +165,17 @@ tibble::tibble(
171
165
172
166
## Issue 2: Period imbalances
173
167
174
-
When comparing two performance periods with a standard calendar, you often will compare a period with unequal number of days or periods. For example if you want to compare January sales to February you can get misleading conclusions due to the unequal number of weekends and days in those periods.
168
+
When comparing two performance periods with a standard calendar, you often will compare a period with unequal number of days or periods.
169
+
170
+
For example if you want to compare January sales to February you can get misleading conclusions due to the unequal number of weekends and days in those periods.
175
171
176
172
> In practice you have two choices:
177
173
>
178
174
- compare periods with similar days (eg. the 28th of February compares should only compare up to the 28th of January) and you omit three days of January sales all together
179
175
>
180
176
- compare have an imbalanced comparison (eg. the 28th of February compares to the 31st of January so that no days are lost).
181
177
182
-
this package does the second option which is ensure we don't loose any of January's sales but to help flag for imbalance, fpaR will add a column to let you know how many periods (eg. days) are in your comparison period to increase transparency to this dynamic.
178
+
This package does the second option to ensure we don't loose any of January's sales but to help flag for imbalance, fpaR will add a column to let you know how many periods (eg. days) are in your comparison period to increase transparency to this dynamic.
183
179
184
180
To create this example, we will use the `pmtd()` function to calculate the prior month to date cumulative margin in the current month.
185
181
@@ -218,22 +214,15 @@ contoso::sales |>
218
214
tinytable::tt(width=1)
219
215
```
220
216
221
-
##what is going on under the hood
217
+
### Issues 3: larger than memory
222
218
223
-
In financial planning and analysis, it is common to compare **year-to-date (YTD)** metrics against the **previous year's YTD**to understand performance trends.
219
+
If your data isn't already in a database then fpaR will leverage duckdb to convert your data to enable larger than memory calculation.
224
220
225
-
The function `yoytd_fn()` provides this functionality. While it is an **internal, non-exported function**, it is called by [yoytd()] and executed through [calculate()].
221
+
This is necessary for time intelligence functions because when you have grouped data, you need to complete calendar for each group combination. For even modest datasets, this can quickly multiple and grow you data to be larger than memory.
226
222
227
-
This vignette explains what the function does, how it works, and how to work with its output.
223
+
If your data is already in database, then fpaR will use [dbplyr](https://dbplyr.tidyverse.org/)and will convert the functions to SQL to write the queries.
228
224
229
-
# Function Purpose
225
+
In either scenario, you can use `dplyr::collect()` to execute your SQL query and return a tibble to your local computer.
Copy file name to clipboardExpand all lines: vignettes/articles/getting_started_with_ti_files/libs/bootstrap/bootstrap-c45587a26a1df833d5e643ccce865553.min.css
0 commit comments