-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path204df_fs.R
96 lines (69 loc) · 2.47 KB
/
204df_fs.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
source("001package.R")
source("202df_tb.R")
# control total----
tb %>%
summarise_at(vars(debit, credit), sum)
# completeness----
yr_fs <- tb %>%
group_by(subaccount) %>%
summarise_at(vars(debit, credit), sum)
# monthly accumulated fs----
mth_fs <- tb %>%
group_by(subaccount, month) %>%
arrange(date) %>%
slice(n()) %>%
ungroup() %>%
select(subaccount, month, balance) %>%
pivot_wider(names_from = month, values_from = balance) %>%
select(subaccount, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec) %>%
replace(is.na(.), 0) # no prior year and market value for the calculation of mscore and zscore
# mutate_all(~(replace_na(.,0)))
# monthly sales----
mth_fs %>%
filter(subaccount == "Revenue") %>%
gather(month, tcredit) %>%
rename(Accumlated_sales = tcredit)
mth_sales <- df_ar %>%
filter(subaccount == "Revenue") %>%
group_by(month) %>%
summarise(monthly_sales = sum(credit)) %>%
janitor::adorn_totals()
# identical(FS, Sales)
# wow comparison----
#+
wow_sales <- df_ar %>%
filter(subaccount == "Revenue") %>%
mutate(weekstarting = floor_date(date, unit = "weeks")) %>%
group_by(weekstarting, name) %>%
summarise(weeklysales = sum(credit)) %>%
arrange(weekstarting, name) %>%
ungroup() %>%
group_by(name) %>%
mutate(mom = (weeklysales - lag(weeklysales)) / lag(weeklysales),
mom = round(mom * 100, 1),
yoy = (weeklysales - lag(weeklysales , 52)) / lag(weeklysales, 52),
yoy = round(yoy * 100, 1))
#+
mom_sales <- df_ar %>%
filter(subaccount == "Revenue") %>%
mutate(yearmonth = format(date, "%Y-%m")) %>%
group_by(yearmonth, name) %>%
summarise(monthlysales = sum(credit)) %>%
arrange(yearmonth, name) %>%
ungroup() %>%
group_by(name) %>%
mutate(mom = (monthlysales - lag(monthlysales)) / lag(monthlysales),
mom = round(mom * 100, 1),
yoy = (monthlysales - lag(monthlysales , 12)) / lag(monthlysales, 12),
yoy = round(yoy * 100, 1))
mom_sales %>%
filter(!is.na(mom)) %>%
select(-yoy) %>% # compare to prior months (not direct prior months)
arrange(desc(abs(mom)))
mom_sales %>%
ggplot(aes(yearmonth, mom, fill = name)) +
geom_col(position = "dodge", show.legend = FALSE) +
geom_text(aes(yearmonth, mom, label = name, angle = 45), check_overlap = TRUE, size = 3, hjust = 0.4, vjust = 0) +
expand_limits(y = 500) +
theme_light() +
theme(axis.text.x = element_text(angle = 90)) # not pretty due to the data