Excel BI - PowerQuery Challenge 280

excel-challenges
power-query
Date Name Data Value Column1 Column2
Published

March 24, 2026

Illustration for Excel BI - PowerQuery Challenge 280

Challenge Description

Date Name Data Value Column1 Column2

Solutions

library(tidyverse)
library(readxl)

path = "Power Query/PQ_Challenge_280.xlsx"
input = read_excel(path, range = "A1:D20")
test = read_excel(path, range = "F1:I12")

result <- input %>%
  mutate(Date = as.Date(Date)) %>%
  nest(data = -Date) %>%
  mutate(
    data = map(
      data,
      ~ pivot_wider(
        .x,
        names_from = Data,
        values_from = Value
      ) %>%
        mutate(across(everything(), as.character)) %>%
        bind_rows(setNames(as.list(names(.)), names(.)), .) %>%
        set_names(paste0("Column", seq_along(.)))
    )
  ) %>%
  unnest(data) %>%
  mutate(Column1 = ifelse(Column1 == "Name", as.character(Date), Column1)) %>%
  select(-Date)
  • 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_280.xlsx"
input = pd.read_excel(path, usecols="A:D", nrows=20)
test = pd.read_excel(path, usecols="F:I", nrows=12)

input['Date'] = pd.to_datetime(input['Date'])
pivot = input.pivot_table(index=['Date', 'Name'], columns='Data', values='Value', aggfunc='sum').reset_index()

new = pd.concat([
    pd.DataFrame({'Date': pivot['Date'].unique(), 'Name': pivot['Date'].unique(), 'Data1': 'Data1', 'Data2': 'Data2', 'Data3': 'Data3'}),
    pivot
], ignore_index=True)

new = new.groupby(['Date', 'Name']).apply(lambda x: x.sort_values(by='Date')).reset_index(drop=True)
new = new.drop(columns=['Date']).set_axis(test.columns, axis=1)

print(new)
  • 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.