library(tidyverse)
library(readxl)
path = "Excel/800-899/845/845 Employee Groups.xlsx"
input = read_excel(path, range = "A2:C14")
test = read_excel(path, range = "E2:G7") %>%
mutate(Name = str_replace_all(Name, " , ", ", "))
result = input %>%
summarise(Name = paste(Name, collapse = ", "),
.by = c(`Dept ID`,`Emp Ind`)) %>%
relocate(Name, .after = `Dept ID`) %>%
arrange(`Dept ID`, `Emp Ind`)
all.equal(result, test, check.attributes = FALSE)
# [1] TRUEExcel BI - Excel Challenge 845
excel-challenges
excel-formulas
🔰 Answer Expected Dept ID Name Emp Ind A C A, C B E B, D

Challenge Description
🔰 Answer Expected Dept ID Name Emp Ind A C A, C B E B, D
Solutions
- Logic: Read the workbook ranges needed for the challenge; Derive the required intermediate columns; Aggregate or rank the data at the required grouping level.
- Strengths: The code maps the workbook rule into a compact, reproducible pipeline.
- Areas for Improvement: The solution assumes the workbook layout and selected ranges remain stable, so any structural change in the sheet would require small adjustments.
- Gem: The elegant part is how little code is needed once the correct intermediate representation is chosen.
import pandas as pd
path = "Excel/800-899/845/845 Employee Groups.xlsx"
input = pd.read_excel(path, usecols="A:C", skiprows=1, nrows=13)
test = pd.read_excel(path, usecols="E:G", skiprows=1, nrows=5).rename(columns=lambda c: c.replace(".1", ""))\
.assign(Name=lambda df: df["Name"].str.replace(r" , ", ", ", regex=True))
result = (
input.groupby(["Dept ID", "Emp Ind"], as_index=False)["Name"]
.agg(", ".join)
.sort_values(["Dept ID", "Emp Ind"])
)[["Dept ID", "Name", "Emp Ind"]]
print(result.equals(test)) # TrueThe Python version follows the same grouped logic and keeps the transformation explicit in a dataframe pipeline.
Difficulty Level
Easy / Medium
The business rule is clear, though the workbook still needs a few transformation steps to reach the expected output.