Youtube Channel: https://www.youtube.com/@DataAnalytic

Video link https://youtu.be/pWiXoYUxs9M

How to create a date table which you can use in PowerBI or anywhere else.

Package needed

We only need ggplot2 package. Use the install packages command as shown below in comments if you do not have the package already installed.

# libraries used
library(dplyr)
library(lubridate)
library(busdater)
library(glue)
start_date <- as.Date("2020-01-01")
end_date <- as.Date("2030-12-31")

fiscal_start_month <- 7
fiscal_start_month_date <- "07-01"


# For financial year fix your fiscal_start_month

df_date_table <- data.frame(date = seq(from = start_date, to  = end_date, by = 'day'))%>%
  dplyr::mutate(n_week_day         = lubridate::wday(date, week_start = 1))%>%
  dplyr::mutate(text_week_day_abbr = lubridate::wday(date, label= TRUE))%>%
  dplyr::mutate(text_week_day_full = lubridate::wday(date, label= TRUE,abbr = FALSE))%>%
  dplyr:::mutate(flag_weekend      = case_when(lubridate::wday(date, label= TRUE) %in% c('Sat','Sun') ~ 'Week-end'
                                       , TRUE ~ 'Week-day'))%>%
  dplyr::mutate(n_iso_week_number = lubridate::isoweek(date))%>%
  dplyr::mutate(n_epi_week_number = lubridate::epiweek(date))%>%
  dplyr::mutate(n_month          = lubridate:::month(date))%>%
  dplyr::mutate(text_month_abbr  = lubridate::month(date, label = TRUE))%>%
  dplyr::mutate(text_month_full  = lubridate::month(date, label = TRUE, abbr = FALSE))%>%
  dplyr::mutate(n_cal_quarter             = lubridate:::quarter(date))%>%
  dplyr::mutate(text_cal_quarter          = glue("Q{lubridate::quarter(date)}"))%>%
  dplyr::mutate(text_cal_year_quarter     = lubridate::quarter(date, type = 'year.quarter'))%>%
  dplyr::mutate(n_fiscal_quarter          = lubridate::quarter(date, fiscal_start = 7))  %>%
  dplyr::mutate(text_fiscal_quarter       = glue("Fisc. Q{lubridate::quarter(date, fiscal_start = fiscal_start_month)}"))%>%
  dplyr::mutate(text_year_fiscal_quarter  = lubridate::quarter(date, type = 'year.quarter',fiscal_start = fiscal_start_month))%>%
  dplyr::mutate(n_cal_semester            = lubridate::semester(date))%>%
  dplyr::mutate(text_cal_semester         = glue("Semester {lubridate::semester(date)}"))%>%
  dplyr::mutate(n_cal_year_semester       = lubridate::semester(date,with_year = TRUE))%>%
  dplyr::mutate(n_cal_year             = lubridate::year(date))%>%
  dplyr::mutate(n_epi_year             = lubridate::epiyear(date))%>%
  dplyr::mutate(n_fiscal_year          = get_fy(date = date
                                        , offset_period = 0
                                        , opt_fy_start = getOption("busdaterFYstart" , default = fiscal_start_month_date)))%>%

  dplyr::mutate(text_fiscal_year       = glue("{n_fiscal_year -1}-{substr(n_fiscal_year,3,4)}"))
library(gt)
## Warning: package 'gt' was built under R version 4.4.1
gt(head(df_date_table))
date n_week_day text_week_day_abbr text_week_day_full flag_weekend n_iso_week_number n_epi_week_number n_month text_month_abbr text_month_full n_cal_quarter text_cal_quarter text_cal_year_quarter n_fiscal_quarter text_fiscal_quarter text_year_fiscal_quarter n_cal_semester text_cal_semester n_cal_year_semester n_cal_year n_epi_year n_fiscal_year text_fiscal_year
2020-01-01 3 Wed Wednesday Week-day 1 1 1 Jan January 1 Q1 2020.1 3 Fisc. Q3 2020.3 1 Semester 1 2020.1 2020 2020 2020 2019-20
2020-01-02 4 Thu Thursday Week-day 1 1 1 Jan January 1 Q1 2020.1 3 Fisc. Q3 2020.3 1 Semester 1 2020.1 2020 2020 2020 2019-20
2020-01-03 5 Fri Friday Week-day 1 1 1 Jan January 1 Q1 2020.1 3 Fisc. Q3 2020.3 1 Semester 1 2020.1 2020 2020 2020 2019-20
2020-01-04 6 Sat Saturday Week-end 1 1 1 Jan January 1 Q1 2020.1 3 Fisc. Q3 2020.3 1 Semester 1 2020.1 2020 2020 2020 2019-20
2020-01-05 7 Sun Sunday Week-end 1 2 1 Jan January 1 Q1 2020.1 3 Fisc. Q3 2020.3 1 Semester 1 2020.1 2020 2020 2020 2019-20
2020-01-06 1 Mon Monday Week-day 2 2 1 Jan January 1 Q1 2020.1 3 Fisc. Q3 2020.3 1 Semester 1 2020.1 2020 2020 2020 2019-20