Excel functions for engineers tutorial with Leila Gharani

Download the Excel for Engineers Workbook

Get the bill of materials dataset from the video with every example worked out: REPT, TRIM, LEN, SUBSTITUTE, LEFT, RIGHT, FIND, LOOKUP, IFERROR and IF.

The 10 functions covered, grouped by job:

  • Format and clean text: REPT, TRIM
  • Count and replace characters: LEN, SUBSTITUTE
  • Extract substrings: LEFT, RIGHT, FIND, SEARCH
  • Look up parent items: LOOKUP
  • Handle errors and conditions: IFERROR, IF

These functions aren’t engineering-only. The same techniques work for any structured text data: SKU codes, account hierarchies, project codes, file paths.

The dataset

The examples use a bill of materials for a trailer assembly. Column A holds the BOM Level (0 through 3) and Column B holds the Part Number.

Excel Bill of Materials dataset with BOM Level numbers in column A and indented Part Numbers in column B showing a four-level product hierarchy

The BOM Level shows the parent-child hierarchy. The Trailer at Level 0 is the parent of Chassis and Wheel Assembly. Wheel Assembly is the parent of Side Piece, which is the parent of Nut, M12.

Tree diagram of the BOM hierarchy from level 0 down to level 3 with part numbers in each box

The dataset also includes Material Category, Weight, Made or Bought, and Quantity. These columns come into play in the LOOKUP and IF examples later in the guide.

How do you indent BOM levels in Excel?

The REPT function allows you to repeat a set of characters as many times as you want.

For our purposes, we want to use REPT to get indented part numbers.  The indents will allow us to visualize our hierarchy more clearly.

To achieve this look manually, we’d have to copy/paste the part numbers into a new column, then add a series of indentations before each part number to achieve the desired indentation level.

This will take a lot of time, energy, and a high likelihood of inducing typographic errors.

Excel column C showing the target indented part number layout with increasing indentation for each BOM level before REPT formula is applied

We can’t feed the REPT function an indentation instruction, but we can use three spaces to simulate an indentation.  This is also a great way to achieve this look because we can easily increase or decrease the indentation by adjusting the number of spaces.

We’ll use the REPT function to add three spaces before the part number if it is a BOM Level “1”, six spaces if it is a BOM Level “2”, and nine spaces if it is a BOM Level “3”.  Level “0” will not be indented.

We begin by inserting a new Column C and writing the following formula in cell C2.

=REPT(" " , 3 * A2) & B2
Excel REPT formula =REPT(" ",3*A2)&B2 in cell C2 using three spaces multiplied by the BOM level to indent each part number to its hierarchy level

The REPT function multiplies the “3” by the BOM Level value then concatenates the part number to the end.

Excel column C filled with REPT formula results showing part numbers indented by 3, 6, and 9 spaces for BOM levels 1, 2, and 3 respectively

How do you remove indents from a BOM list?

The TRIM function removes leading and trailing spaces from text. It also cuts extra spaces between words down to a single space.

If your part numbers come indented, like the REPT result above, add a blank column and use TRIM to get a flat list:

=TRIM(B2)
Excel TRIM formula =TRIM(B2) in a new column removing all leading spaces from the indented part numbers to produce a flat unindented list

This produces a list of flattened part numbers having had all the leading spaces removed from the hierarchy.

Excel column filled with TRIM formula results showing all part numbers flattened to the same indentation level with no leading spaces

Tip: Some PLM and ERP exports use non-breaking spaces, which TRIM does not remove. Swap them for normal spaces first:

=TRIM(SUBSTITUTE(B2, CHAR(160), “ “))

How do you count WBS levels from dot notation?

The LEN function will return the number of characters in a text string while the SUBSTITUTE function will replace a character or string of characters with another character or string of characters.

If we were given a file where the hierarchy was displayed more like WBS (Work Breakdown Structure) codes, but we need the numbers as we’ve seen in earlier examples, we can write a formula to produce these numbers.

Excel WBS code list in column B showing hierarchical codes with periods such as 1, 1.1, 1.1.1 used as the data source for the LEN SUBSTITUTE formula

Each period starts a new level.  An item with no periods is considered “Level 0” while an item with two periods is considered “Level 2”.

The logic for this substitution is as follows:

  1. Insert a new column (in this example, Column A).
  2. In cell A2, count the number of characters in the cell. This will be done using the LEN function.
  3. Replace all the “dots” with nothing. This will be done using the SUBSTITUTE function using two consecutive double quotes to symbolize nothing.  Two continuous double quotes mean “empty text” to Excel.  It’s like saying “show nothing”.
  4. Using the LEN function, count the number of remaining characters after the dots have been removed.
  5. Subtract the result from Step 4 from the result in Step 2.
=LEN(B2) - LEN(SUBSTITUTE(B2, ".", "") )
Excel formula =LEN(B2)-LEN(SUBSTITUTE(B2,".","")) in cell A2 counting the number of periods in each WBS code to determine the BOM level

Our results are as follows:

Excel column A filled with LEN SUBSTITUTE formula results showing the correct BOM level number derived from period count for each WBS code

How do you split part numbers from descriptions in Excel?

The LEFT function extracts a set number of characters from a text string starting from the left side of the text.

We have been given a small table of Part Identities and quantities.

Excel Part Identity table with combined part number and description text in column A separated by a comma used as source data for LEFT FIND extraction

We need to separate the Part Number from the Description.  These two elements are together in a single cell separated by a comma.

Excel Part Identity table with a new Part Number column added in column D as the target for the LEFT FIND formula extraction results

Finding the Part Numbers

To separate the part numbers, we’ll start a new table (in Column D) and use the FIND function to locate the character position of the comma.

=FIND(",", A2)

We can then use this value to tell the LEFT function how many characters to extract from the left of cell A2.

=LEFT(A2, FIND(",", A2) )

We must deduct one from the value returned by FIND to not include the comma in the results.

=LEFT(A2, FIND(",", A2) - 1)
Excel formula =LEFT(A2,FIND(",",A2)-1) in cell D2 extracting only the part number from the combined text by stopping one character before the comma

PRO TIP: The FIND function is case-sensitive.  If you need to locate a character or string of text in a case-insensitive fashion, use the SEARCH function.  The syntax and use are the same as the FIND function.

Excel column D filled with LEFT FIND formula results showing clean part numbers extracted from the combined Part Identity column without the comma

Finding the Descriptions

The key is to extract all characters after the comma.

We can use FIND to locate the comma as before.  This will give us a count of all characters up to and including the comma.

=FIND(",", A2)

The result of this FIND can be subtracted from the length of the entire text string to yield the number of characters to extract.

=LEN(A2) - FIND(",", A2)

This value will be used by RIGHT to perform the extraction of the characters determined by LEN & FIND.

=RIGHT( A2, LEN(A2) - FIND(",", A2) )
Excel formula =RIGHT(A2,LEN(A2)-FIND(",",A2)) in cell E2 extracting the description from the combined text by taking all characters after the comma

The results are as follows:

Excel table with both the part number and description columns populated showing the successful split of the combined Part Identity text into two clean columns

Modern alternative: TEXTBEFORE and TEXTAFTER

If you have Excel for Microsoft 365 or Excel 2024, TEXTBEFORE and TEXTAFTER replace the LEFT/RIGHT/FIND combo with one cleaner formula:

=TEXTBEFORE(A2, ",")
=TEXTAFTER(A2, ",")

Same result, no LEN math, no character offset to remember. The LEFT/RIGHT/FIND approach still works in older Excel versions, so it’s worth knowing both.

How do you find the parent part in a BOM hierarchy?

Discovering Data Using the LOOKUP Function

There will be many occasions where you need to discover an unknown piece of information based on a known piece of information.

An example may be something as simple as “How much does this chocolate chip cookie cost?”, or something more involved like “How many of this particular part number do we have in stock?”

Simple or involved, these questions can be solved using a lookup function.

Lookup functions have been part of Excel since its inception. Many methods have been developed over the years to discover related information. Functions like:

Each of these functions has its strengths and weaknesses.  Choosing the right one depends on the task at hand coupled with your knowledge and comfort level with each function.

The simplest (and oldest) lookup function is called LOOKUP.  LOOKUP has lost favor over the years as more sophisticated, more capable functions have arrived on the scene.  But that doesn’t mean it has lost its value.

LOOKUP lacks the pretentiousness of other functions, like INDEX/MATCH.  Its charm is in its simplicity.

LOOKUP has the following syntax:

LOOKUP( lookup_value, lookup_vector, [result_vector] )

In simpler terms:

  • lookup_value: the thing you know, like a part number, employee number or cost code.
  • lookup_vector: the single row or column where the lookup_value may sit.
  • result_vector (optional): the single row or column that holds the result you want.

For more detailed information and example on the use of LOOKUP, see the Microsoft Documentation for Excel’s LOOKUP function.

For our example, we want to discover the part number for the immediate parent of any child-level part number.

Excel BOM table with purple highlights on BOM level 0 Trailer row and its child items illustrating the parent-child relationship to be solved with LOOKUP
  • Level 1’s parent is Level 0
  • Level 2’s parent is Level 1
  • Level 3’s parent is Level 2

To discover this, we can take the BOM Level of a child item (ex: Part Number “10410-1001” on row 7 has a BOM Level of “1”) and locate the nearest level “0” BOM Level that is above the current row.

Using the example above, the nearest BOM Level “0” is on row 2, Part Number “10420-1001”.  (See the purple entries in the previous image.)

We can’t just write a lookup function that finds the first BOM Level that is 1 less than the current BOM Level.

At BOM Level “2”, there can be many level “1” entries above the current row.  We must locate the closest (i.e., last listed) parent-level value that is above our current position.

We would need to ignore the level “1” item on row 3 and discover the level “1” item on row 7.

Excel BOM table with purple and green highlights showing multiple level 1 items above a level 2 row illustrating why the last matching parent must be found

The formula we will use here is more sophisticated than most users are accustomed to.  Perhaps a future post will break down the logic with greater specificity.

For now, we’ll just type it in as it relates to a lookup range in a LOOKUP function without diving into the details.

Starting in cell C2 of our example, we’ll write the following formula:

=LOOKUP(2, 1 / ($A$2:A2 = A2 - 1), $B$2:B2)

The components are:

  • lookup_value: 2
  • lookup_vector: 1/($A$2:A2=A2-1)
  • [result_vector]: $B$2:B2
Excel LOOKUP formula =LOOKUP(2,1/($A$2:A2=A2-1),$B$2:B2) in cell C2 finding the nearest parent-level part number above each row in the BOM hierarchy

Hitting ENTER and filling the formula down the column produces the following results.

Excel column C filled with LOOKUP formula results showing correct parent part numbers for each child row and a DIV0 error in the first row

Observe the #DIV/0! error on row 2.

Excel cell C2 showing a DIV0 error highlighted in the BOM table because BOM level 0 has no parent item for the LOOKUP formula to find

This is because BOM Level “0” has no parent-level item.

We can suppress this error message using the IFERROR function.

Displaying Custom Error Messages Using the IFERROR Function

Because many of the default Excel error messages are less than helpful to most users, we can trap the ugly error message and replace it with most anything we wish.

This is accomplished using the IFERROR function.  IFERROR allows us to test a formula’s result.  If the result is one of Excel’s built-in error messages, we can substitute the error with one of the following:

  • Nothing (empty text)
  • A text response
  • A static value
  • A different action via a formula

Since we know our BOM Level “0” items will return errors, we will trap the original errors and replace them with dashes.

=IFERROR(LOOKUP(2, 1 / ($A$2:A2 = A2 - 1), $B$2:B2), "-")
Excel IFERROR formula wrapping the LOOKUP to replace the DIV0 error with a dash using =IFERROR(LOOKUP(2,1/($A$2:A2=A2-1),$B$2:B2),"-")

Now we have a more pleasing dash instead of an ugly error message.

Excel column C showing the updated IFERROR LOOKUP results with a dash in the first row replacing the DIV0 error for the BOM level 0 Trailer row

How do you flag top-level parts and calculate rollup quantities?

IF functions allow you to ask a question then to act in one of two possible ways depending on the answer.

For our first example, we’ll perform a very simple IF that tests to see if the BOM Level is equal to a zero.

We’ll write the following in cell I2 and fill it down the column.

=IF(A2=0, "YES", "NO")
Excel IF formula =IF(A2=0,"YES","NO") in cell I2 returning YES for BOM level 0 items and NO for all child-level items in the hierarchy

Bonus: Calculate Extended Quantities

Let’s look at an example where we use three of the previously mentioned function in a single formula.

  • IF
  • IFERROR
  • LOOKUP

We’ll create a formula that calculates the quantity for each part at each level.  The logic goes like this:

  1. If a BOM Level “1” has a quantity of 4, and
  2. its associated BOM Level “2” has a quantity of 2, and
  3. its associated BOM Level “3” has a quantity of 2, then
  4. each level is a multiple of its quantity against all previous quantities.

If we have a quantity of 4 at level “1”, and a quantity of 2 at level “2”, then we need 8 total at level “2”.

If we then need 8 at level “2”, and we have a quantity of 2 at level “3”, then we need 16 total at level “3”.

=IF(A2 = 0, H2, IFERROR(H2 * LOOKUP(2, 1 / ($A$1:A1 = (A2 - 1) ), $I$1:I1), "-") )

Enter it in a new column I (Extended Qty), right after the Qty column H. The formula looks up the extended quantity of the parent in the rows above, in its own column. The Top level column from the IF example moves one column to the right.

Excel bonus formula =IF(A2=0,H2,IFERROR(H2*LOOKUP(2,1/($A$1:A1=(A2-1)),$I$1:I1),"-")) combining IF IFERROR and LOOKUP to calculate cumulative quantities

We’re using many of the same ideas presented earlier but in a more sophisticated way.

Excel column I filled with cumulative quantity results showing each part's total required quantity multiplied across all parent levels of the BOM hierarchy

Download the Practice Workbook

Download the Excel for Engineers Workbook

Get the BOM dataset and practice all ten functions on real part data.

Frequently Asked Questions

What Excel functions do engineers use most?

Engineers use text functions such as REPT, TRIM, LEN, SUBSTITUTE, LEFT, RIGHT, FIND and SEARCH to clean part data, lookup functions such as LOOKUP, VLOOKUP, XLOOKUP and INDEX MATCH to trace parent items, and IF and IFERROR to flag conditions and handle errors. Calculation-heavy work also uses SUMPRODUCT, CONVERT and the IM functions for complex numbers.

How do you indent rows in Excel based on a BOM level?

Use REPT to repeat a space a fixed number of times per level and join the part number to it. With three spaces per level, level 0 stays flush left, level 1 indents three spaces and level 2 indents six. The exact formula is in the REPT section above.

How do you count the number of dots in a WBS code?

Subtract the length of the code without dots from the length of the original. LEN counts the characters and SUBSTITUTE removes the dots, so the difference is the number of dots, which equals the WBS level.

What is the difference between FIND and SEARCH in Excel?

FIND is case-sensitive and SEARCH is not. Both return the position of a character within a text and use the same syntax. SEARCH also accepts wildcards. Use FIND when case matters and SEARCH when it does not.

How do you find the parent part of an item in a BOM hierarchy?

Use LOOKUP with the 2 and 1/ trick: =LOOKUP(2, 1/($A$2:A2=A2-1), $B$2:B2). It returns the closest part above the current row that sits one level higher. Wrap it in IFERROR for level 0 items, which have no parent.

Are there modern Excel alternatives to LEFT, RIGHT and FIND?

Yes. TEXTBEFORE and TEXTAFTER, available in Excel for Microsoft 365, Excel 2024 and Excel for the web, replace most LEFT, RIGHT and FIND combinations. TEXTBEFORE returns everything before a delimiter such as a comma, and TEXTAFTER returns everything after it.

Leila Gharani

Founder of XelPlus and ten-time Microsoft MVP. Leila helps over 500,000 professionals master Excel, Power BI, and data automation through practical, real-world training.