Excel BI - Excel Challenge 835

excel-challenges
excel-formulas
🔰 List the employees getting the highest salary in each department.
Published

March 24, 2026

Illustration for Excel BI - Excel Challenge 835

Challenge Description

🔰 List the employees getting the highest salary in each department.

Solutions

library(tidyverse)
library(readxl)

path = "Excel/800-899/835/835 Max Salary.xlsx"
input = read_excel(path, range = "A2:C12")
test  = read_excel(path, range = "E2:G6")

result = input %>%
  fill(Dept) %>%
  slice_max(order_by = Salary, n = 1, with_ties = T, by = Dept) %>%
  mutate(Dept = if_else(row_number() == 1, Dept, NA_character_), .by = Dept) %>%
  rename(`Max Salary` = Salary)

all.equal(result, test)
# [1] TRUE
  • 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 = "800-899/835/835 Max Salary.xlsx"

input = pd.read_excel(path, usecols="A:C", skiprows=1, nrows=11)
test = pd.read_excel(path, usecols="E:G", skiprows=1, nrows=4).rename(columns=lambda x: x.replace('.1', ''))

input['Dept'] = input['Dept'].ffill()
result = input[input.groupby('Dept')['Salary'].transform('max') == input['Salary']].reset_index(drop=True)
result['Dept'] = result['Dept'].where(~result['Dept'].duplicated())
result = result.rename(columns={'Salary': 'Max Salary'})

print(result.equals(test)) # True

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