Crispo - Excel Challenge 41 2024

excel-challenges
weekly-exercises
Easy Sunday Excel Challenge
Published

October 13, 2024

Illustration for Crispo - Excel Challenge 41 2024

Challenge Description

Easy Sunday Excel Challenge

⭐ Problem Solution Date Instance Units Opening

Solutions

library(tidyverse)
library(readxl)

path = "files/Excel Challenge October 13th.xlsx"
input = read_excel(path, range = "B2:D16")
test  = read_excel(path, range = "F2:G16")

result = input %>%
  fill(Date, .direction = "down") %>%
  group_by(Date) %>%
  mutate(open = first(Units)) %>%
  mutate(Units = ifelse(is.na(Instance) , open + Units, Units)) %>%
  select(Date, Units)

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

    • Reads the workbook range needed for the challenge

    • Aggregates or ranks values at the correct grouping level

    • Builds the intermediate helper columns that drive the final answer

  • 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

path = "files/Excel Challenge October 13th.xlsx"
input = pd.read_excel(path, usecols="B:D", skiprows=1, nrows=15)
test = pd.read_excel(path, usecols="F:G", skiprows=1, nrows=15).rename(columns=lambda x: x.replace('.1', ''))

input['Date'] = input['Date'].ffill()
input['open'] = input.groupby('Date')['Units'].transform('first')
input['Units'] = input.apply(lambda row: row['open'] + row['Units'] if pd.isna(row['Instance']) else row['Units'], axis=1)

result = input[['Date', 'Units']]

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

    • Reads the workbook range needed for the challenge

    • Aggregates or ranks values at the correct grouping level

  • 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.