Ravindra BagaleCourses & study guides

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

After

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

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).