Crispo - Excel Challenge 39 2024

excel-challenges
weekly-exercises
Easy Sunday Excel Challenge
Published

September 29, 2024

Illustration for Crispo - Excel Challenge 39 2024

Challenge Description

Easy Sunday Excel Challenge

⭐ ⭐Extract the Date and Amount from the details

Solutions

library(tidyverse)
library(readxl)
library(rebus.datetimes)

path = "files/Excel Challenge September 29th.xlsx"
input = read_excel(path, range = "B2:B6")
test  = read_excel(path, range = "D2:E6")


date_patt = digit(1, 2) %R% "/" %R% digit(1, 2) %R% "/" %R% digit(4,4)
amount_patt = SPACE %R% one_or_more(DIGIT) %R% or(SPACE, END)

result = input %>%
  mutate(Date = str_extract(`Revenues Details`, date_patt) %>% mdy() %>% as.POSIXct(),
         Amount = str_extract(`Revenues Details`, amount_patt) %>% as.numeric()) %>%
  select(-`Revenues Details`)

all.equal(result, test, check.attributes = FALSE)
#> [1] TRUE
  • Logic:

    • Reads the workbook range needed for the challenge

    • Builds the intermediate helper columns that drive the final answer

    • Uses direct text-pattern extraction instead of manual cleanup

  • Strengths:

    • The R solution stays compact and mirrors the workbook logic closely.
  • Areas for Improvement:

    • The code assumes the workbook layout and named ranges remain stable.
  • Gem:

    • The best part of the solution is choosing a tidy intermediate shape before producing the final answer.
import pandas as pd
import re

path = "files/Excel Challenge September 29th.xlsx"

input = pd.read_excel(path, usecols="B", skiprows=1, nrows=5)
test = pd.read_excel(path, usecols="D:E", skiprows=1, nrows=5)

date_patt = r'\d{1,2}/\d{1,2}/\d{4}'
amount_patt = r'\d+(?=\s|$)'

input['Date'] = input['Revenues Details'].apply(lambda x: pd.to_datetime(re.search(date_patt, x).group(), format='%m/%d/%Y') if re.search(date_patt, x) else None)
input['Amount'] = input['Revenues Details'].apply(lambda x: re.search(amount_patt, x).group().strip() if re.search(amount_patt, x) else None)
input['Amount'] = input['Amount'].astype('float64')

result = input.iloc[:, 1:]

print(result.equals(test)) # True
  • Logic:

    • Reads the workbook range needed for the challenge

    • Uses direct text-pattern extraction instead of manual cleanup

  • Strengths:

    • The Python version keeps the same rule in a direct pandas-oriented workflow.
  • Areas for Improvement:

    • As with the R version, any workbook layout change would require small adjustments.
  • Gem:

    • The implementation stays close to the stated challenge instead of adding unnecessary complexity.

Difficulty Level

This task is moderate:

  • It combines familiar Excel-style logic with at least one non-trivial reshape, grouping, or parsing step.

  • The answer depends on getting the output layout exactly right.