library(tidyverse)
library(readxl)
path = "Power Query/PQ_Challenge_218.xlsx"
input = read_excel(path, range = "A1:C17")
test = read_excel(path, range = "E1:G5") %>%
replace_na(list(`Completed Tasks` = "", `Not Completed Tasks` = ""))
result = input %>%
mutate(has_date = ifelse(is.na(`Completion Date`), "Not Completed Tasks", "Completed Tasks")) %>%
select(-`Completion Date`) %>%
pivot_wider(names_from = has_date, values_from = Tasks, values_fn = list) %>%
mutate(`Completed Tasks` = map_chr(`Completed Tasks`, ~paste(.x, collapse = ", ")),
`Not Completed Tasks` = map_chr(`Not Completed Tasks`, ~paste(.x, collapse = ", ")))
identical(result, test)
#> [1] TRUEExcel BI - PowerQuery Challenge 218
excel-challenges
power-query
Transpose the table as shown. If a task is completed, its Completion Date is non blank.

Challenge Description
Transpose the table as shown. If a task is completed, its Completion Date is non blank.
Solutions
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_218.xlsx"
input = pd.read_excel(path, usecols="A:C")
test = pd.read_excel(path, usecols="E:G", nrows=4).rename(columns=lambda x: x.replace(".1", ""))
input["Status"] = input["Completion Date"].apply(lambda x: "Not Completed Tasks" if pd.isnull(x) else "Completed Tasks")
input = input.drop(columns="Completion Date").pivot_table(index="Project", columns="Status", aggfunc=lambda x: ', '.join(map(str, x)))
input.columns = input.columns.droplevel()
input = input.reset_index().rename_axis(None, axis=1)
print(input.equals(test)) # TrueLogic:
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.