Excel BI - Excel Challenge 808

excel-challenges
excel-formulas
🔰 Fruits are followed by weights separated by comma.
Published

March 24, 2026

Illustration for Excel BI - Excel Challenge 808

Challenge Description

🔰 Fruits are followed by weights separated by comma. List the Fruits and their total weights and sort on Fruits.

Solutions

library(tidyverse)
library(readxl)

path = "Excel/800-899/808/808 Group By Fruits.xlsx"
input = read_excel(path, range = "A2:A18")
test  = read_excel(path, range = "C2:D8")

result = input %>%
  separate_longer_delim(Data, delim = ", ") %>%
  mutate(measure = ifelse(str_detect(Data, "^[0-9]+$"), "Weight", "Fruits")) %>%
  mutate(rn = row_number(), .by = measure) %>%
  pivot_wider(names_from = measure, values_from = Data) %>%
  summarise(`Total Weight` = sum(as.numeric(Weight)), .by = Fruits) %>%
  arrange(Fruits)

all.equal(result, test)
# TRUE
  • Logic: Read the workbook ranges needed for the challenge; Derive the required intermediate columns; Parse the packed text or string structure; Aggregate or rank the data at the required grouping level.
  • Strengths: The reshaping step mirrors the workbook output closely instead of forcing extra post-processing.
  • Areas for Improvement: The solution assumes the workbook layout and selected ranges remain stable, so any structural change in the sheet would require small adjustments.
  • Gem: The last reshape turns a raw transformation into something that already looks like a report.
import pandas as pd

path = "800-899/808/808 Group By Fruits.xlsx"
input = pd.read_excel(path, usecols="A", skiprows=1, nrows=16, names=["Data"])
test = pd.read_excel(path, usecols="C:D", skiprows=1, nrows=6)

input = input.dropna()['Data'].str.split(', ', expand=True).stack().reset_index(drop=True)
fruits = input[~input.str.isdigit()].reset_index(drop=True)
weights = input[input.str.isdigit()].astype(int).reset_index(drop=True)
result = pd.DataFrame({'Fruits': fruits, 'Weight': weights})
result = result.groupby('Fruits', as_index=False)['Weight'].sum().rename(columns={'Weight': 'Total Weight'}).sort_values('Fruits').reset_index(drop=True)

print(result.equals(test)) # True

The Python version follows the same grouped logic and keeps the transformation explicit in a dataframe pipeline.

Difficulty Level

Medium

The individual steps are manageable, but the correct transformation pattern is not obvious from the raw data.