library(tidyverse)
library(readxl)
path = "Power Query/300-399/310/PQ_Challenge_310.xlsx"
input = read_excel(path, range = "A1:D13")
test = read_excel(path, range = "F1:I6")
result = input %>%
fill(Name, .direction = "down") %>%
group_by(Name) %>%
fill(c(Gender, Age, Salary), .direction = "downup") %>%
ungroup() %>%
distinct()
all.equal(result, test)
#> [1] TRUEExcel BI - PowerQuery Challenge 310
excel-challenges
power-query
Name Gender Age Salary Atkins F

Challenge Description
Name Gender Age Salary Atkins F
Solutions
Logic:
Reads the workbook range needed for the challenge
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/310/PQ_Challenge_310.xlsx"
input = pd.read_excel(path, usecols="A:D", nrows=13)
test = pd.read_excel(path, usecols="F:I", nrows=5).rename(columns=lambda col: col.replace('.1', ''))
input['Name'] = input['Name'].ffill()
input[['Gender', 'Age', 'Salary']] = input.groupby('Name')[['Gender', 'Age', 'Salary']]\
.bfill().ffill()
result = input.drop_duplicates().reset_index(drop=True)
result[['Age', 'Salary']] = result[['Age', 'Salary']].astype(int)
print(result.equals(test)) # TrueLogic:
Reads the workbook range needed for the challenge
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.