library(tidyverse)
library(readxl)
path = "files/Ex-Challenge 01 2025.xlsx"
input = read_excel(path, range = "B2:E14")
test = read_excel(path, range = "G2:J8")
result = input %>%
mutate(across(c(Invoice, Posted, Dept), ~trimws(.))) %>%
unite("name", c("Invoice", "Posted", "Dept"), sep = "_") %>%
group_by(name) %>%
filter(n() == 1 | (n() == 2 & sum(Value) != 0)) %>%
separate("name", c("Invoice", "Posted", "Dept"), sep = "_")
all.equal(result, test)
#> [1] TRUECrispo - Excel Challenge 01 2025
excel-challenges
weekly-exercises
Easy Sunday Excel Challenge

Challenge Description
Easy Sunday Excel Challenge
⭐ Invoice Posted Dept Value INV-001 JSMITH
Solutions
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/Ex-Challenge 01 2025.xlsx"
input = pd.read_excel(path, usecols="B:E", skiprows=1, nrows=12)
test = pd.read_excel(path, usecols="G:J", skiprows=1, nrows=6)\
.rename(columns=lambda x: x.replace('.1', ''))\
.apply(lambda x: x.str.strip() if x.name == 'Invoice' else x)
input['name'] = input[['Invoice', 'Posted', 'Dept']]\
.apply(lambda x: x.str.strip()).astype(str)\
.agg('_'.join, axis=1)
grouped = input.groupby('name')\
.filter(lambda x: len(x) == 1 or (len(x) == 2 and x['Value'].sum() != 0))
result = grouped.copy().assign(**grouped['name'].str.split('_', expand=True).rename(columns={0: 'Invoice', 1: 'Posted', 2: 'Dept'}))\
.drop(columns=['name']).reset_index(drop=True)
print(result.equals(test)) # TrueLogic:
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 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.