Excel BI - PowerQuery Challenge 321

excel-challenges
power-query
Seq Date ID1 ID2 ID3 ID4
Published

March 24, 2026

Illustration for Excel BI - PowerQuery Challenge 321

Challenge Description

Seq Date ID1 ID2 ID3 ID4

Solutions

library(tidyverse)
library(readxl)

path = "Power Query/300-399/321/PQ_Challenge_321.xlsx"
input = read_excel(path, range = "A1:G8")
test  = read_excel(path, range = "K1:P5") %>%
  mutate(across(everything(), ~ replace_na(.x, "")))

result = input %>%
  summarise(across(starts_with("ID"), 
                   ~ paste0(na.omit(.x), collapse = ", ")), 
            .by = Date)

all_equal(result, test)
# TRUE
  • Logic:

    • Reads the workbook range needed for the challenge

    • Aggregates or ranks values at the relevant grouping level

    • 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 = "300-399/321/PQ_Challenge_321.xlsx"

input = pd.read_excel(path, usecols="A:G", nrows=8)
test = pd.read_excel(path, usecols="K:P", nrows=4).fillna("").rename(columns=lambda c: c.replace(".1", ""))

id_cols = [col for col in input.columns if col.startswith("ID")]
result = (
    input.groupby("Date")[id_cols]
    .agg(lambda x: ", ".join(x.dropna().astype(str)))
    .reset_index()
)

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

    • Reads the workbook range needed for the challenge

    • Aggregates or ranks values at the relevant grouping level

    • Applies the rule iteratively until the output is complete

  • 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 easy to moderate:

  • The transformation rule is readable, but the final layout still requires a careful implementation.