Excel BI - PowerQuery Challenge 325

excel-challenges
power-query
Employee Date Task1_Hours Task1_Project Task2_Hours Task2_Project
Published

March 24, 2026

Illustration for Excel BI - PowerQuery Challenge 325

Challenge Description

Employee Date Task1_Hours Task1_Project Task2_Hours Task2_Project

Solutions

library(tidyverse)
library(readxl)

path = "Power Query/300-399/325/PQ_Challenge_325.xlsx"
input = read_excel(path, range = "A1:H4")
test  = read_excel(path, range = "A9:B13")

result = input %>%
  pivot_longer(cols = -c(Employee, Date), 
               names_to = c("Task", ".value"),
               names_pattern = "(.*)_(.*)", 
               values_drop_na = T) %>%
  summarise(Hours = sum(Hours, na.rm = TRUE), .by = Project) %>%
  rename(Projects = Project) %>%
  janitor::adorn_totals("row")

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

    • Reads the workbook range needed for the challenge

    • Reshapes the data into the structure required by the result table

    • Aggregates or ranks values at the relevant grouping level

  • Strengths:

    • The R solution stays close to the workbook logic and keeps the transformation compact.
  • Areas for Improvement:

    • The code assumes the workbook layout and selected ranges remain stable.
  • Gem:

    • The best part of the solution is choosing the right intermediate shape before formatting the final output.
import pandas as pd

path = "300-399/325/PQ_Challenge_325.xlsx"
input = pd.read_excel(path, usecols="A:H", nrows=4)
test = pd.read_excel(path, usecols="A:B", skiprows=8, nrows=5)

df = input.melt(id_vars=["Employee", "Date"], var_name="name", value_name="value")
df[["Task", "var"]] = df["name"].str.split("_", expand=True)
df = df.pivot(index=["Employee", "Date", "Task"], columns="var", values="value").reset_index()
result = df.groupby("Project", as_index=False).agg(Hours=("Hours", "sum")).rename(columns={"Project": "Projects"})
result["Hours"] = result["Hours"].astype(int)
result = pd.concat([result, pd.DataFrame([{"Projects": "Total", "Hours": result["Hours"].sum()}])], ignore_index=True)

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

    • Reads the workbook range needed for the challenge

    • Reshapes the data into the structure required by the result table

    • Aggregates or ranks values at the relevant grouping level

  • Strengths:

    • The Python version follows the same workbook rule in a direct pandas-oriented implementation.
  • Areas for Improvement:

    • As with the R version, any workbook layout change would require small adjustments.
  • Gem:

    • The implementation stays close to the source challenge instead of adding unnecessary abstraction.

Difficulty Level

This task is moderate:

  • It combines reshaping, grouping, or parsing steps that are common in Power Query style problems.

  • The main challenge is reproducing the workbook output structure exactly.