Topic: excel tutorials
Summary: In this post, I’ll walk you through how to use **Excel functions** like **LEN**, **AVERAGE**, and **IF** to perform simple yet powerful data analysis. This tutorial builds off of the **VLOOKUP** [tutorial](https://mightyanalyst.com/post/how-to-use-the-vlookup-function-in-excel-) but you can start on this one if you please. In this example, we’ll explore how to calculate the length of capital city names and compare them to the average length using an **IF** statement.
If you prefer video, check out the youtube tutorial Download the file to follow along: Download
To figure out which capital city names are longer than the average, the first step is to calculate the length of each city name.
=LEN(F2)
This will calculate the length of the text string in cell F2
(the city name).The LEN function gives you the length (number of characters) in each capital name.
Next, we’ll calculate the average length of the capital city names.
=AVERAGE(G:G)
In this example, G:G
refers to the range where the lengths of the city names are located.The AVERAGE function returns the average number of characters in the city names.
Now that we know the length of each city name and the average, we’ll use an IF statement to classify whether each capital name is longer or shorter than the average.
H2
).=IF(G2>$J$2, "Long", "Short")
In this formula:G2
is the length of the city name.$J$2
is the cell containing the average length (the dollar signs lock the reference to this cell so it doesn’t move when copied).Now, each row will return either "Long" or "Short" based on the comparison with the average.
If you followed allong you should be fine, but if you find that the formula isn’t working as expected, it's likely because of relative references. As you copy the formula down, Excel adjusts the cell references unless you lock them. Here’s how you can avoid this problem:
Ensure that you use absolute referencing for the cell containing the average value by placing dollar signs ($
) before the column and row references, like this:
$N$2
This locks the reference so that every comparison will be made against the correct average value.
After making this adjustment, check if the IF statement now works correctly across all rows.
=LEN(F2)
=AVERAGE(G:G)
=IF(G2>$J$2, "Long", "Short")
By using a combination of LEN, AVERAGE, and IF functions, you can easily analyze text data and compare values in Excel. These are powerful tools that allow you to perform logical tests and make comparisons based on custom conditions. Check out the video tutorial linked below for a step-by-step demonstration of how to apply these formulas in Excel.