library(tidyverse)
library(readxl)
path = "files/Ex-Challenge 07 2025.xlsx"
input = read_excel(path, range = "B3:B14")
test = read_excel(path, range = "D3:D18")
result = input %>%
mutate(group = cumsum(c(1, diff(Staff) < 0)),
Staff = as.character(Staff)) %>%
group_by(group) %>%
group_split() %>%
imap_dfr(~ {
dynamic_row <- tibble(
Staff = paste("GROUP", .y),
group = unique(.x$group)
)
bind_rows(.x, dynamic_row)
}) %>%
select(Groups = Staff)
all.equal(result, test)
# [1] TRUECrispo - Excel Challenge 07 2025
excel-challenges
weekly-exercises
Easy Sunday Excel Challenge

Challenge Description
Easy Sunday Excel Challenge
⭐ Groups ⭐Group the staff and insert the group name after last count ⭐The end of a group is always before No. 1 ⭐The last group has only 1 staff GROUP 1 GROUP 2
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 07 2025.xlsx"
input = pd.read_excel(path, usecols="B", skiprows=2, nrows=11)
test = pd.read_excel(path, usecols="D", skiprows=2, nrows=15).astype(str)
input['group'] = (input['Staff'].diff() < 0).cumsum() + 1
input['Staff'] = input['Staff'].astype(str)
result = input.groupby('group', group_keys=False).apply(
lambda x: x._append(pd.DataFrame({'Staff': [f"GROUP {x.name}"]}))
).reset_index(drop=True)[['Staff']].rename(columns={'Staff': 'Groups'})
print(result.equals(test))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.