Excel BI - PowerQuery Challenge 220

excel-challenges
power-query
Project Activities Start Finish A Fabrication
Published

March 24, 2026

Illustration for Excel BI - PowerQuery Challenge 220

Challenge Description

Project Activities Start Finish A Fabrication

Solutions

library(tidyverse)
library(readxl)

path = "Power Query/PQ_Challenge_220.xlsx"
input = read_excel(path, range = "A1:D9")
test  = read_excel(path, range = "A13:I18") %>% replace(is.na(.), "")

result = input %>%
  mutate(Start = floor_date(Start, "month"),
         Finish = floor_date(Finish, "month")) %>%
  mutate(seq = map2(Start, Finish, seq, by = "month")) %>%
  unnest(seq) %>%
  select(-Start, -Finish) %>%
  mutate(rn = row_number(), .by = c("Project", "seq")) %>%
  pivot_wider(names_from = seq, values_from = Activities, values_fill = "") %>%
  select(-rn)

names(result) = names(test)

result == test
# two cells in wrong order.
  • Logic:

    • Reads the workbook range needed for the challenge

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

    • Builds helper columns that drive the final output

  • 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 = "PQ_Challenge_220.xlsx"
input = pd.read_excel(path, sheet_name=0, usecols="A:D", nrows=9)
test = pd.read_excel(path, sheet_name=0, usecols="A:I", skiprows=12, nrows=6).fillna("")

input[['Start', 'Finish']] = input[['Start', 'Finish']].apply(pd.to_datetime).apply(lambda x: x.dt.to_period('M').dt.to_timestamp())

input = input.assign(seq=input.apply(lambda x: pd.date_range(x['Start'], x['Finish'], freq='MS'), axis=1)).explode('seq').drop(columns=['Start', 'Finish'])

input['rn'] = input.groupby(['Project', 'seq']).cumcount() + 1

result = input.pivot_table(index=['Project', 'rn'], columns='seq', values='Activities', aggfunc=lambda x: ' '.join(x)).fillna('').reset_index()
result.columns.name = None
result = result.drop(columns='rn')
result.columns = test.columns

print(result == test) # two cells in wrong order
  • 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

    • Builds helper columns that drive the final output

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