Excel BI - PowerQuery Challenge 247

excel-challenges
power-query
Name Question Option Chosen Q1 Q2 Q3
Published

March 24, 2026

Illustration for Excel BI - PowerQuery Challenge 247

Challenge Description

Name Question Option Chosen Q1 Q2 Q3

Solutions

library(tidyverse)
library(readxl)

path = "Power Query/PQ_Challenge_247.xlsx"
input1 = read_excel(path, range = "A1:C13")
input2 = read_excel(path, range = "A16:B20")
test  = read_excel(path, range = "E1:J4")

input = input1 %>%
  left_join(input2, by = "Question") %>%
  mutate(correctness = ifelse(`Option Chosen` == `Correct Option`, "Y", "N")) %>%
  select(-c(3:4)) %>%
  pivot_wider(names_from = Question, values_from = correctness, names_prefix = "Q") %>%
  mutate(Score = rowSums(select(., starts_with("Q")) == "Y"))

all.equal(input, test)
#> [1] TRUE
  • 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_247.xlsx"
input1 = pd.read_excel(path, usecols="A:C", nrows=13)
input2 = pd.read_excel(path, usecols="A:B", skiprows=15, nrows=5)
test = pd.read_excel(path, usecols="E:J", nrows=3).rename(columns=lambda x: x.split('.')[0])

input = input1.merge(input2, on="Question", how="left")
input['correctness'] = (input['Option Chosen'] == input['Correct Option']).map({True: 'Y', False: 'N'})
input = input.drop(columns=['Option Chosen', 'Correct Option'])
input = input.pivot(index='Name', columns='Question', values='correctness').rename(columns=lambda x: f"Q{x}")
input['Score'] = (input == 'Y').sum(axis=1)
input.reset_index(inplace=True)

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

    • Reads the workbook range needed for the challenge

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

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