library(tidyverse)
library(readxl)
library(fuzzyjoin)
path = "files/CH-087 Price List.xlsx"
input1 = read_excel(path, range = "B2:D9")
input2 = read_excel(path, range = "G2:I11")
test = read_excel(path, range = "J2:J11")
result = input2 %>%
fuzzy_left_join(input1, by = c("Product" = "Product", "Date" = "From Date"),
match_fun = list(`==`, `>=`)) %>%
filter(`From Date` == max(`From Date`), .by = c("Product.x", "Date"))
identical(result$Price, test$Price)
# [1] TRUEOmid - Challenge 87
data-challenges
advanced-exercises
🔰 From Date Product Price A B Date Quantity Question Table: Price List

Challenge Description
🔰 From Date Product Price A B Date Quantity Question Table: Price List
Solutions
Logic:
- Reads the workbook ranges needed for the challenge
Strengths:
- The R solution stays close to the workbook rule and keeps the transformation compact.
Areas for Improvement:
- The code assumes the sheet structure and source ranges remain stable.
Gem:
- The strongest part of the solution is choosing the right intermediate representation before shaping the final output.
import pandas as pd
path = 'CH-087 Price List.xlsx'
input1 = pd.read_excel(path, usecols= "B:D", skiprows= 1, nrows = 7)
input2 = pd.read_excel(path, usecols= "G:I", skiprows= 1, nrows = 9)
input2.columns = input2.columns.str.replace(".1", "")
test = pd.read_excel(path, usecols= "J", skiprows= 1, nrows = 9)
test.columns = test.columns.str.replace(".1", "")
result = input2.merge(input1, on = "Product", how = "left")\
.loc[lambda df: df['Date'] >= df['From Date']]\
.groupby(['Product', 'Date']).max()\
.sort_values(by = ['Date'], ascending = [True])\
.reset_index()
print(result["Price"].equals(test["Price"])) # TrueLogic:
Reads the workbook ranges needed for the challenge
Aggregates or ranks values at the relevant grouping level
Strengths:
- The Python version follows the same rule in a direct dataframe-oriented implementation.
Areas for Improvement:
- The code assumes the workbook layout remains stable, so any sheet redesign would require small adjustments.
Gem:
- The implementation stays close to the original workbook rule instead of adding unnecessary abstraction.
Difficulty Level
This task is moderate:
- The business rule is readable, but the workbook still requires careful implementation to reach the expected layout.