Ravindra BagaleCourses & study guides मराठी Track your progress

5. Data Cleaning A–Z

5.13 Extracting Parts of Text

Before

Order Note
Order BLK-260314-001 delivered in 9 mins
Order AMN-260314-006 delivered in 10 mins
Order BLK-260314-005 delivered in 18 mins

About this data: Teaching sample for a fictional shop “FreshGo Mart”. Figures and names (e.g. Sana Sheikh) are made up for this lesson on extracting parts of text.

After

Order ID Mins
BLK-260314-001 9
AMN-260314-006 10
BLK-260314-005 18

About this data: Demo table only — not real customer or company data. Built to practise extracting parts of text.

Steps in Excel

  1. Order ID (always 14 characters, starting after "Order "): =MID(A2,7,14).
  2. Minutes between "in " and " mins": =VALUE(MID(A2,FIND("in ",A2)+3,FIND(" mins",A2)-FIND("in ",A2)-3)).
  3. Microsoft 365 / Excel 2024: =TEXTBEFORE(TEXTAFTER(A2,"Order ")," ") and =--TEXTBEFORE(TEXTAFTER(A2,"in ")," mins").
  4. Or Flash Fill with two examples.

Ravindra Bagale's Tip

Many students hard-code the positions (7, 14), and when one note is written differently the answer goes wrong. Hard-code only if you are sure the length is fixed; otherwise find the "markers" with FIND or TEXTBEFORE/TEXTAFTER. Turn the extracted number into a real number with VALUE – otherwise you can't average it.

Practice task

From notes like "Rider Raja delivered BLK-260314-007 at 19:51", extract the rider name, the order ID and the time (as a real time value).

Loading practice tasks...

  1. First word (Easy): Get the first 5 characters of A2.
  2. Order number (Easy): Get the order number from A2 (start 7, length 9).
  3. Last word (Easy): Get the last 3 characters of A3.
  4. Length of the message (Easy): How many characters are in A4?
  5. Order number as a number (Medium): Get the order number from A3 as a number.
  6. Position of " in " (Medium): Find the position of " in " in A2.
  7. Text after "in " (Medium): Get the text after "in " in A2.
  8. Order number with TEXTBEFORE (Medium): Get the text before " delivered" in A4, after "ORDER ".
  9. Minutes as a number (Hard): Get the minutes from A2 as a number.
  10. Minutes for a 1-digit order (Hard): Get the minutes from A3 as a number.
  11. Late delivery? (Hard): Is the order in A5 late? (TRUE or FALSE)

Quick revision cards

Three standalone cards. Each one explains the idea with its own example. Scan the QR to open this lesson.

Revision card 1: What is Extracting Parts Of Text?
Card 1: What is Extracting Parts Of Text? · Download PNG
Revision card 2: Tiny example — Extracting Parts Of Text
Card 2: Tiny example — Extracting Parts Of Text · Download PNG
Revision card 3: Checklist — Extracting Parts Of Text
Card 3: Checklist — Extracting Parts Of Text · Download PNG