Skip to content

Commit 5629fbe

Browse files
committed
554 first steps, new augment calendar columns
1 parent 941a092 commit 5629fbe

21 files changed

+3669
-114
lines changed

554.R

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
library(tidyverse)
2+
library(contoso)
3+
devtools::document()
4+
5+
devtools::load_all()
6+
7+
8+
9+
## create 5-5-4 calendar
10+
11+
x <- contoso::sales |> fpaR::mtd(order_date,revenue,calendar_type = "standard")
12+
13+
14+
con <- dbplyr::remote_con(x@datum@data)
15+
16+
# complete calendar with all attributes
17+
18+
new_cal <- fpaR:::seq_date_sql(start_date = "2025-01-01",end_date = "2025-12-31",time_unit = "day",con =con ) |>
19+
augment_calendar(.date = date)
20+
21+
22+
## next step add in new year indicator
23+
new_cal |>
24+
dplyr::mutate(
25+
new_year_date_indicator=if_else(month_of_year==2&day_of_year==4,1,0)
26+
,.before=1
27+
)
28+
29+
## next step add in new year indicator
30+
31+
32+
33+
## add in period indicator for that

R/utils-misc.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ lubridate::days
235235
,week_end_date=lubridate::ceiling_date({{.date}},unit = "week")-1
236236
,day_of_week=lubridate::wday({{.date}},label = FALSE)
237237
,day_of_week_label=lubridate::wday({{.date}},label = TRUE)
238+
,day_of_year=lubridate::day({{.date}})
239+
,month_of_year_label_abb=lubridate::month({{.date}},label = TRUE,abbr = TRUE)
240+
,month_of_year_label_full_name=lubridate::month({{.date}},label=TRUE,abbr = FALSE)
241+
,month_of_year=lubridate::month({{.date}},label=FALSE)
238242
,days_in_year=year_end_date-year_start_date
239243
,days_in_quarter=quarter_end_date-quarter_start_date
240244
,days_in_month=lubridate::days_in_month({{.date}})
@@ -247,6 +251,7 @@ lubridate::days
247251
,days_complete_in_quarter={{.date}}-quarter_start_date
248252
,days_complete_in_month={{.date}}-month_start_date
249253
,days_complete_in_year={{.date}}-year_start_date
254+
250255
,weekend_indicator=dplyr::if_else(day_of_week_label %in% c("Saturday","Sunday"),1,0)
251256
) |>
252257
dplyr::mutate(
@@ -324,6 +329,10 @@ augment_calendar_dbi <- function(.data,.date){
324329
,week_end_date=dplyr::sql(glue::glue("date_trunc('month', {date_vec}) + INTERVAL '1' month"))
325330
,day_of_week=lubridate::wday({{.date}},label = FALSE)
326331
,day_of_week_label=lubridate::wday({{.date}},label = TRUE)
332+
,day_of_year=lubridate::day({{.date}})
333+
,month_of_year_label_abb=lubridate::month({{.date}},label = TRUE,abbr = TRUE)
334+
,month_of_year_label_full_name=lubridate::month({{.date}},label=TRUE,abbr = FALSE)
335+
,month_of_year=lubridate::month({{.date}},label=FALSE)
327336
,days_in_year=year_end_date-year_start_date
328337
,days_in_quarter=quarter_end_date-quarter_start_date
329338
,days_in_month=dplyr::sql(glue::glue("last_day({date_vec})"))

README.md

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ Under the hood, these functions are built upon the great foundations of:
2929
- [duckdb](https://github.com/duckdb/duckdb-r)
3030
- [lubridate](https://lubridate.tidyverse.org/)
3131

32-
`fpaR` is designed to seamlessly work with either tibbles or modern
33-
databases (DuckDB, Snowflake, SQLite, etc) with a unified syntax
32+
`fpaR` is designed to work with either tibbles or modern databases
33+
(DuckDB, Snowflake, SQLite, etc) with a unified syntax
3434

3535
Even if you are working with tibbles, most functions are optimized to
36-
leverage [DuckDB](https://github.com/duckdb/duckdb-r) for superior speed
37-
and performance.[^1]
36+
leverage [DuckDB](https://github.com/duckdb/duckdb-r) for increased
37+
speed and performance[^1]
3838

3939
By default most `fpaR` function returns a lazy DBI object which you can
4040
return as a tibble with `dplyr::collect()`
@@ -60,19 +60,19 @@ pak::pak("usrbinr/fpaR")
6060

6161
## What is in fpaR?
6262

63-
There are 3 main categories of functions:
64-
65-
- Time intelligence
66-
- Segmentation strategies
67-
- Factor analysis (work in progress)
68-
69-
### Datasets
70-
7163
> We recommend using the [Contoso](https://usrbinr.github.io/contoso/)
7264
> package for any practice analysis. The contoso datasets are fictional
7365
> business transaction of Contoso toy company which are helpful for
7466
> business intelligence related analysis
7567
68+
There are 3 main categories of functions:
69+
70+
- Time intelligence realted functions
71+
(<a href="#tbl-ti-fn" class="quarto-xref">Table 1</a>)
72+
- Categorization strategies
73+
(<a href="#tbl-abc-fn" class="quarto-xref">Table 2</a>)
74+
- Factor analysis (work in progress)
75+
7676
### Time intelligence
7777

7878
`fpaR` provides readily available functions for most time intelligence
@@ -99,6 +99,12 @@ intelligence related analysis in a consistent, fast and transparent way
9999

100100
Below is the full list of time intelligence functions:
101101

102+
<div id="tbl-ti-fn">
103+
104+
Table 1
105+
106+
<div class="cell-output-display">
107+
102108
| Function | Description | Shift | Aggregate | Compare |
103109
|----|----|----|----|----|
104110
| YoY | Full Year over Year | | | X |
@@ -123,6 +129,10 @@ Below is the full list of time intelligence functions:
123129
| ATD | cumlaitve total from inception to date | | x | |
124130
| DoD | Full Day over Full Day | | | X |
125131

132+
</div>
133+
134+
</div>
135+
126136
### **Segmentation Strategies**
127137

128138
#### ABC Classification
@@ -147,11 +157,21 @@ product or service
147157
This allows you to understand retention, turnover and other attributes
148158
more clearly
149159

160+
<div id="tbl-abc-fn">
161+
162+
Table 2
163+
164+
<div class="cell-output-display">
165+
150166
| Function | Description | Categorizes | Time-Based | Tracks Over Time |
151167
|----|----|----|----|----|
152168
| abc() | ABC Classification groups items by relative contribution (Pareto analysis). | X | | |
153169
| cohort() | Cohort analysis groups entities by a shared start point and analyzes behavior over time. | | X | X |
154170

171+
</div>
172+
173+
</div>
174+
155175
------------------------------------------------------------------------
156176

157177
### **Factor / Variation Analysis**

README.qmd

Lines changed: 34 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -21,47 +21,33 @@ library(tidyverse)
2121

2222
## A Business Intelligence Toolkit for Financial Planning & Analysis (FP&A)
2323

24-
`fpaR` is a collection of business intelligence tools designed to
25-
simplify common **financial planning and analysis (FP&A)** tasks such as
26-
time intelligence calculations, customer, vendor or product
27-
segmentation, and factor/variance analysis
24+
`fpaR` is a collection of business intelligence tools designed to simplify common **financial planning and analysis (FP&A)** tasks such as
25+
time intelligence calculations, customer, vendor or product segmentation, and factor/variance analysis
2826

29-
The package is inspired by best practices from a collection of blogs,
30-
books, industry research, and hands-on work experience, consolidating
31-
frequently performed business analyses into a fast, efficient, and
32-
reusable framework
27+
The package is inspired by best practices from a collection of blogs, books, industry research, and hands-on work experience, consolidating frequently performed business analyses into a fast, efficient, and reusable framework
3328

34-
In particular, the time intelligence functions are heavily inspired by
35-
[PowerBI DAX](https://www.sqlbi.com/) functions
29+
In particular, the time intelligence functions are heavily inspired by [PowerBI DAX](https://www.sqlbi.com/) functions
3630

3731
Under the hood, these functions are built upon the great foundations of:
3832

3933
- [dbplyr](https://dbplyr.tidyverse.org/)\
4034
- [duckdb](https://github.com/duckdb/duckdb-r)
4135
- [lubridate](https://lubridate.tidyverse.org/)
4236

43-
`fpaR` is designed to seamlessly work with either tibbles or modern
44-
databases (DuckDB, Snowflake, SQLite, etc) with a unified syntax
37+
`fpaR` is designed to work with either tibbles or modern databases (DuckDB, Snowflake, SQLite, etc) with a unified syntax
4538

46-
Even if you are working with tibbles, most functions are optimized to
47-
leverage [DuckDB](https://github.com/duckdb/duckdb-r) for superior speed
48-
and performance.[^1]
39+
Even if you are working with tibbles, most functions are optimized to leverage [DuckDB](https://github.com/duckdb/duckdb-r) for increased speed
40+
and performance[^1]
4941

50-
[^1]: I plan to use [duckplyr](https://duckplyr.tidyverse.org/index.html)
51-
once it expands support for lubricate functions
42+
[^1]: I plan to use [duckplyr](https://duckplyr.tidyverse.org/index.html) once it expands support for lubricate functions
5243

53-
By default most `fpaR` function returns a lazy DBI object which you can
54-
return as a tibble with `dplyr::collect()`
44+
By default most `fpaR` function returns a lazy DBI object which you can return as a tibble with `dplyr::collect()`
5545

5646
## Key features & benefits
5747

58-
- **Unified syntax** regardless if your data is in a tibble or a
59-
database
60-
- **Scale** your data with
61-
[duckdb](https://github.com/duckdb/duckdb-r) to optimize your
62-
calculations
63-
- **Instant clarity** as every function summarizes its transformation
64-
actions so that you can understand and validate the results
48+
- **Unified syntax** regardless if your data is in a tibble or a database
49+
- **Scale** your data with [duckdb](https://github.com/duckdb/duckdb-r) to optimize your calculations
50+
- **Instant clarity** as every function summarizes its transformation actions so that you can understand and validate the results
6551

6652
## Installation
6753

@@ -80,45 +66,29 @@ pak::pak("usrbinr/fpaR")
8066

8167
## What is in fpaR?
8268

69+
> We recommend using the [Contoso](https://usrbinr.github.io/contoso/) package for any practice analysis. The contoso datasets are fictional business transaction of Contoso toy company which are helpful for business intelligence related analysis
70+
8371
There are 3 main categories of functions:
8472

85-
- Time intelligence
86-
- Segmentation strategies
73+
- Time intelligence realted functions (@tbl-ti-fn)
74+
- Categorization strategies (@tbl-abc-fn)
8775
- Factor analysis (work in progress)
8876

8977

90-
### Datasets
91-
92-
> We recommend using the
93-
[Contoso](https://usrbinr.github.io/contoso/) package for any practice
94-
analysis. The contoso datasets are fictional business transaction of
95-
Contoso toy company which are helpful for business intelligence
96-
related analysis
97-
98-
99-
10078
### Time intelligence
10179

102-
`fpaR` provides readily available functions for most time intelligence
103-
analysis such as **Year-over-Year**(`yoy()`), **Month-to-Date**(`mtd()`), and
104-
**Current Year-to-Date over Previous Year-to-Date** (`ytdopy()`) analysis
80+
`fpaR` provides readily available functions for most time intelligence analysis such as **Year-over-Year**(`yoy()`), **Month-to-Date**(`mtd()`), and **Current Year-to-Date over Previous Year-to-Date** (`ytdopy()`) analysis
10581

106-
These functions are designed to quickly answer most common time
107-
intelligence related analysis in a consistent, fast and transparent way
82+
These functions are designed to quickly answer most common time intelligence related analysis in a consistent, fast and transparent way
10883

10984
**Key benefits:**
11085

111-
- **Auto-fill missing dates**: Ensures no missing periods in your
112-
datasets so that right period comparisons are performed
86+
- **Auto-fill missing dates**: Ensures no missing periods in your datasets so that right period comparisons are performed
11387

114-
- **Flexible calendar options**: Handle comparisons based on a
115-
**standard** or **5-5-4** fiscal calendar to accommodate different
116-
reporting frameworks
88+
- **Flexible calendar options**: Handle comparisons based on a **standard** or **5-5-4** fiscal calendar to accommodate different reporting frameworks
89+
90+
- **Full transparency**: Comparing periods with imbalaced dates? the time intelligence functions will alert you to the type and number of period imbalances to ensure you are aware of misleading likewise comparisons and prints out detials of each function's actions and methods to avoid confusion
11791

118-
- **Period imbalance indicator**: When comparing periods with dates
119-
imbalance, the time intelligence functions will alert you to the
120-
type and number of period imbalances to ensure you are aware of
121-
misleading likewise comparisons
12292

12393
Below is the full list of time intelligence functions:
12494

@@ -127,7 +97,7 @@ Below is the full list of time intelligence functions:
12797
#| warning: false
12898
#| message: false
12999
#| error: false
130-
#| label: ti-fn
100+
#| label: tbl-ti-fn
131101
132102
tibble::tribble(
133103
~"Function", ~"Description", ~"Shift", ~"Aggregate", ~"Compare",
@@ -183,27 +153,28 @@ tibble::tribble(
183153
184154
```
185155

156+
------------------------------------------------------------------------
186157

187-
### **Segmentation Strategies**
158+
### **Classification Strategies**
188159

189160
#### ABC Classification
190161

191-
ABC classification is an business analysis technique that categorizes items (like products, customers, or suppliers) based on their relative contribution of a value. It facilities the Pareto Principle (the 80/20 rule), suggesting that a small percentage of items contribute to the largest percentage of the total value
162+
ABC classification is an business analysis technique that categorizes items (like products, customers, or suppliers) based on their relative contribution of a value. It expands upon the the Pareto Principle (the 80/20 rule), allowing the user to determine which percentage of items or group members contribute to the largest percentage of the total value
192163

193-
The analysis will assign a letter category to each break point so that you can further focus your analysis
164+
You assign the break points for the categorization and the function will label each category with a letter value
194165

195166
#### Cohort
196167

197-
Cohort analysis is a type of behavioral analytics that takes data from a given group of users (a cohort) and tracks their activity over time. A cohort is typically defined by a shared starting characteristic, most commonly the time period in which the entities first interacted with the product or service
168+
Cohort analysis is a type of behavioral analytics that takes data from a given group of users (called a cohort) and tracks their activity over time. A cohort is typically defined by a shared starting characteristic, most commonly the time period in which the entities first interacted with the product or service
198169

199-
This allows you to understand retention, turnover and other attributes more clearly
170+
This allows you to understand retention, turnover and other cohort attributes more clearly
200171

201172
```{r}
202173
#| echo: false
203174
#| warning: false
204175
#| message: false
205176
#| error: false
206-
#| label: abc-fn
177+
#| label: tbl-abc-fn
207178
208179
tibble::tribble(
209180
~"Function", ~"Description", ~"Categorizes", ~"Time-Based", ~"Tracks Over Time",
@@ -229,17 +200,16 @@ tibble::tribble(
229200
### **Factor / Variation Analysis**
230201

231202
Breaks down revenue or cost changes into **price, volume, and mix
232-
effects**.
203+
effects**
204+
205+
Work in progress.
233206

234207
------------------------------------------------------------------------
235208

236209
## Future capabilities
237210

238211
Is there a future capability that you want to see here? please open up a [discussion](https://github.com/usrbinr/fpaR/discussions) on our github site
239212

240-
241-
242213
## Additional references and inspirations
243214

244-
- [PeerChristensen's Cohort
245-
Package](https://github.com/PeerChristensen/cohorts)
215+
- [PeerChristensen's Cohort Package](https://github.com/PeerChristensen/cohorts)

man/create_calendar.Rd

Lines changed: 1 addition & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/print.Rd

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)