Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

`with_year` argument to quarter should results in quarter year not calendar year #890

Closed
vspinu opened this issue May 4, 2020 · 1 comment
Closed
Labels

Comments

@vspinu
Copy link
Member

@vspinu vspinu commented May 4, 2020

From https://community.rstudio.com/t/fiscal-year-quarters-not-aligned-to-calendar-quarters/60530

This is how it works in excel:


data.frame(dt = ymd(c("2018-07-15", "2018-12-27", "2019-01-01",
                      "2019-06-01", "2019-07-01", "2019-10-16",
                      "2019-12-31", "2020-01-01", "2020-06-30",
                      "2020-07-01", "2020-11-09", "2021-01-19",
                      "2021-06-30", "2021-07-01")),
           expected = c("2019-Q1", "2019-Q2", "2019-Q3",
                        "2019-Q4", "2020-Q1", "2020-Q2",
                        "2020-Q2", "2020-Q3", "2020-Q4",
                        "2021-Q1", "2021-Q2", "2021-Q3",
                        "2021-Q4", "2022-Q1")) %>%
  mutate(actual = quarter(dt, with_year = T, fiscal_start = 7))

##            dt expected actual
## 1  2018-07-15  2019-Q1 2018.1
## 2  2018-12-27  2019-Q2 2018.2
## 3  2019-01-01  2019-Q3 2019.3
## 4  2019-06-01  2019-Q4 2019.4
## 5  2019-07-01  2020-Q1 2019.1
## 6  2019-10-16  2020-Q2 2019.2
## 7  2019-12-31  2020-Q2 2019.2
## 8  2020-01-01  2020-Q3 2020.3
## 9  2020-06-30  2020-Q4 2020.4
## 10 2020-07-01  2021-Q1 2020.1
## 11 2020-11-09  2021-Q2 2020.2
## 12 2021-01-19  2021-Q3 2021.3
## 13 2021-06-30  2021-Q4 2021.4
## 14 2021-07-01  2022-Q1 2021.1

The solution is to add an extra argument or allow with_year = "natural" or something like that. Alternative naming is welcome. Otherwise I will use "calendar" for default current behavior or "natural" for this new behavior.

@vspinu vspinu added the feature label May 4, 2020
@vspinu vspinu modified the milestone: 1.7.8 May 4, 2020
@vspinu vspinu closed this in 8045b8a Jun 1, 2020
@vspinu
Copy link
Member Author

@vspinu vspinu commented Jun 1, 2020

The current behavior is actually bogus. The expected behavior is that of Excel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.