library(tidyverse)
library(readxl)
path = "files/200-299/257/CH-257 Date Calculation.xlsx"
test = read_excel(path, range = "B2:B14") %>%
mutate(Dates = as.Date(Dates))
eom = ceiling_date(ymd(paste(2025, 1:12, 1, sep = "-")), "month") - 1
last_mondays = eom - days((wday(eom) - 2) %% 7)
all.equal(last_mondays, test$Dates, check.attributes = FALSE)
#> [1] TRUEOmid - Challenge 257
data-challenges
advanced-exercises
🔰 Result Dates Challenge 257: Date Calculation!

Challenge Description
🔰 Result Dates Challenge 257: Date Calculation!
Solutions
Logic:
Reads the workbook ranges needed for the challenge
Builds the intermediate columns that drive the final result
Strengths:
- The R solution stays close to the workbook rule and keeps the transformation compact.
Areas for Improvement:
- The code assumes the sheet structure and source ranges remain stable.
Gem:
- The strongest part of the solution is choosing the right intermediate representation before shaping the final output.
import pandas as pd
path = "200-299/257/CH-257 Date Calculation.xlsx"
test = pd.read_excel(path, usecols="B", skiprows=1, nrows=12)
result = pd.DataFrame({
"Result": [
(d - pd.Timedelta(days=d.weekday() % 7)).to_datetime64()
for d in pd.date_range("2025-01-31", "2025-12-31", freq="ME")
]
})
print(result["Result"].equals(test["Dates"])) # TrueLogic:
Reads the workbook ranges needed for the challenge
Applies the rule iteratively until the output stabilizes
Strengths:
- The Python version follows the same rule in a direct dataframe-oriented implementation.
Areas for Improvement:
- The code assumes the workbook layout remains stable, so any sheet redesign would require small adjustments.
Gem:
- The implementation stays close to the original workbook rule instead of adding unnecessary abstraction.
Difficulty Level
This task is moderate:
- The business rule is readable, but the workbook still requires careful implementation to reach the expected layout.