1. Lighthouse

Level 3 · Codes, slugs and keyword flags

The request

From Andrew Ramos, Marketing Manager

“Three things for the Decor and Textiles pages before the autumn campaign: a short tracking code per product like tex-161, a URL slug from the name (lowercase, hyphens for spaces), and a flag on everything made of the keyword in I1. We're starting with oak.”

Your goal

In D2:D41, build the tracking code: the first 3 letters of the category in lowercase, a hyphen, then the product_id. In E2:E41, build the slug: the name in lowercase with every space replaced by a hyphen. In F2:F41, return "yes" when the name contains the keyword in I1 as a whole word, otherwise "no" (use IF, ISNUMBER and SEARCH).

  • Fill D2:F41 with the right valuesnot done yet
  • With formulas, not typed numbersnot done yet
  • Use LOWER SUBSTITUTE SEARCH ISNUMBERnot done yet

Your sheet

Excel
The sheet for this level
ABCDEFGHIJ
1product_idnamecategorycodeslughas_keywordKeywordoak
2161Cove Jute Duvet CoverTextiles
3162Oakley Jute Knit ThrowTextiles
4163Pine Cotton Area RugTextiles
5164Cove Wool Lumbar PillowTextiles
6165Weston Cashmere-Blend QuiltTextiles
7166Harbor Wool Knit ThrowTextiles
8167Elm Cashmere-Blend Area RugTextiles
9168Upland Percale Lumbar PillowTextiles
10169Spruce Wool Duvet CoverTextiles
11170Rowan Cashmere-Blend Throw BlanketTextiles
12171Driftwood Percale Area RugTextiles
13172Maple Wool Throw PillowTextiles
14173Bramble Percale QuiltTextiles
15174Vale Cashmere-Blend Knit ThrowTextiles
16175Glen Cotton Runner RugTextiles
17176Fairhaven Cotton Throw PillowTextiles
18177Delancey Cashmere-Blend Duvet CoverTextiles
19178Sutton Wool Knit ThrowTextiles
20179Delancey Jute Area RugTextiles
21180Hazel Linen Throw PillowTextiles
22181Cedar Marble Bud VaseDecor
23182Nantucket Brass Wall MirrorDecor
24183Glen Glass Canvas PrintDecor
25184Thatcher Oak CandleDecor
26185Ridge Brass Bud VaseDecor
27186Birch Brass Floor MirrorDecor
28187Ashford Oak Canvas PrintDecor
29188Fern Oak Candle Holder SetDecor
30189Northfield Brass Bud VaseDecor
31190Elm Brass Floor MirrorDecor
32191Hazel Ceramic Canvas PrintDecor
33192Thatcher Marble Candle Holder SetDecor
34193Delancey Brass VaseDecor
35194Chester Brass Wall MirrorDecor
36195Fairhaven Soy Wax Framed PrintDecor
37196Pine Glass Candle Holder SetDecor
38197Ridge Soy Wax VaseDecor
39198Harbor Oak Floor MirrorDecor
40199Oakley Brass Framed PrintDecor
41200Cedar Ceramic CandleDecor
42
43

Loading the editor…

    ResultPress Check to compare D2:F41

    Mote checks your result

    Press Check. Each right cell becomes a firefly in your lantern.

    The lesson

    Andrew’s ticket is three columns, each built from text that is already in the sheet. The trick in all three is not a new function but functions inside functions. Excel evaluates the innermost one first and hands its answer outward, which lets you do in one cell what would otherwise take two or three helper columns.

    A code from part of a column

    The category in C2 is Textiles. Andrew wants tex-161:

    D2   =LOWER(LEFT(C2,3))&"-"&A2

    Read it from the inside: LEFT(C2,3) is Tex, LOWER turns it into tex, then & adds a hyphen and the product_id. Standardising case is the point of LOWER here: if one export says TEXTILES and another Textiles, both still give tex, and codes that should match do match. Decor products get dec-181 and so on.

    A slug with SUBSTITUTE

    SUBSTITUTE(text, old, new) replaces every occurrence of old with new:

    E2   =LOWER(SUBSTITUTE(B2," ","-"))

    Cove Jute Duvet Cover becomes cove-jute-duvet-cover. Row 6, Weston Cashmere-Blend Quilt, already has a hyphen; it stays, and the slug is weston-cashmere-blend-quilt. SUBSTITUTE takes an optional fourth argument to replace only one occurrence: SUBSTITUTE(B2," ","-",1) changes the first space only.

    The same nesting cleans free text such as review comments. =TRIM(LOWER(review)) lowercases the text, removes spaces at both ends and collapses runs of spaces inside it to one, and wrapping that in SUBSTITUTE(…,"!!","!") fixes a habit Excel has no function for. Chapter 5 is all about that kind of cleaning.

    Does the name contain a word?

    SEARCH(find, within) returns the position where find starts, or #VALUE! when it isn’t there. ISNUMBER turns that into TRUE or FALSE, and IF into the words you want:

    =IF(ISNUMBER(SEARCH($I$1,B2)),"yes","no")

    It works on row 25, Thatcher Oak Candle. Now look at row 3: B3 is Oakley Jute Knit Throw, and oak is inside Oakley, so the formula says “yes” for a throw made of jute. The same happens in row 40, Oakley Brass Framed Print.

    The fix is to search for the word with a space on each side, inside the name with a space added at each end, so a word at the start or the end of the name still has spaces around it:

    F2   =IF(ISNUMBER(SEARCH(" "&$I$1&" "," "&B2&" ")),"yes","no")

    Now " oak " is found in " Thatcher Oak Candle " but not in " Oakley Jute Knit Throw ". Filled down, 4 of the 40 products get “yes”. Change I1 to brass and the column follows: 8 products.

    FIND SEARCH
    Upper and lower case must match: FIND("oak","Oak") is #VALUE! ignored
    Wildcards * and ? no yes

    The names say Oak and the keyword cell says oak, so SEARCH is the right one. Use FIND when case matters, for example to tell the code ABC from abc.

    Common mistakes

    • No ISNUMBER. =IF(SEARCH(…),"yes","no") returns #VALUE! on every row without the word, because the error flows through IF.
    • Partial words. oak matches Oakley, and elm would match Helmsley. Pad with spaces when you mean a whole word.
    • LOWER on the wrong piece. =LEFT(LOWER(C2),3) works too, but =LOWER(LEFT(C2),3) has the 3 in the wrong function: count the brackets.
    • Typing the keyword into the formula. Keep it in I1 and lock it, so the next campaign is one cell away.

    Pick what may run on this site. You can change this any time from "Cookie settings" at the bottom of every page.