How to use the HARMEAN function
What is the HARMEAN function?
The HARMEAN function lets you calculate the harmonic mean in Excel.
Table of contents
1. Introduction
What is the harmonic mean?
The harmonic mean is a type of average that is useful for rates and ratios. It is calculated by taking the reciprocals of the values, averaging them, and reciprocating the result.
It gives more weight to smaller values compared to the arithmetic mean. The harmonic mean is useful when averaging rates and ratios instead of direct values.
The harmonic mean is always less than or equal to the arithmetic mean for a dataset. It is sensitive to small values which can skew or bias the average. Applications for the harmonic mean are averaging speed, fuel efficiency, ratios, and rates.
How is the harmonic mean calculated?
It is calculated by is calculated by dividing the number of values by the reciprocal of each value. For example, calculating the harmonic mean from numbers 2, 4, and 8 equals approx. 3.429
Here is how: 3/(1/2+1/4+1/8) equals approx. 3.429
To calculate the harmonic mean by hand use this formula:
H - harmonic mean
x1, x2, ..., xn - are the numbers
n is the number of values
What is the difference between the harmonic mean and the arithmetic mean (average)?
The difference between the harmonic mean and the arithmetic mean is that the harmonic mean is calculated by dividing the number of values by the reciprocal of each value, whereas the arithmetic mean is calculated by dividing the sum of all values by the number of values.
Divide 1 by the number to get the reciprocal of a number. Example the reciprocal of 4 is 1/4.
The AVERAGE function lets you calculate the arithmetic mean in Excel.
When to calculate the harmonic mean?
The harmonic mean is often the most useful measure for rates and ratios. It gives greater weight to smaller values in a given data set.
How is the weighted harmonic mean calculated?
The weighted harmonic mean is a variation of the regular harmonic mean that takes into account the relative weight of each data point. It is calculated using the following formula:
Weighted Harmonic Mean = n / Σ(wi / xi)
Where:
n is the sum of the weights (Σwi)
wi is the weight associated with each data point xi
xi is the value of the i-th data point
The steps to calculate the weighted harmonic mean are:
- Assign a weight (wi) to each data point (xi) based on their relative importance or significance.
- Calculate the reciprocal of each data point (1/xi).
- Multiply each reciprocal (1/xi) by its corresponding weight (wi).
- Sum up the weighted reciprocals from step 3: Σ(wi / xi)
- Calculate the sum of the weights: Σwi
- Divide the sum of the weights (Σwi) by the sum of the weighted reciprocals from step 4: n / Σ(wi / xi)
2. Syntax
HARMEAN(number1, [number2], ...)
3. Arguments
Argument | Description |
number1 | Required. A single numerical value or a cell reference to multiple numerical values. |
[number2] | Optional. Up to 254 additional arguments. |
Text, logical values and empty cells are ignored.
The HARMEAN function returns
- #NUM! error value if number is less than or equal to 0 (zero).
4. Example 1
A manufacturing plant produces three different types of components. The production rates (units per hour) for each type are as follows: Type A: 50, 60, 70 Type B: 45, 55, 65 Type C: 40, 50, 60 Calculate the harmonic mean of the production rates for each type of component?
The image above shows the production rates in cell range B15:F18, the column chart shows the different production rates grouped in category A, B and C.
Formula in cell F16:
The formula in cell F16 calculates the harmonic mean based on the following production rates: 50, 60, and 70. The calculation is 3/(1/50+1/60+1/70) equals approx 58.88
The formula in cell F17 returns the harmonic mean based on these production rates: 45, 55, and 65. The calculation is 3/(1/45+1/55+1/65) equals approx 53.77
The formula in cell F18 returns the harmonic mean based on these production rates: 40, 50, and 60. The calculation is 3/(1/40+1/50+1/60) equals approx 48.65
5. Example 2
A car travels at 10 mph (miles per hour) for 1 mile, 30 mph for 5 miles, and 50 mph for 2 miles. The total distance is 8 miles. What is the average speed?
The formula for calculating the distance: Distance = Speed x Time
This gives us: Speed = Distance / Time
The total distance is 1 + 5 + 2 equals 8.
The time it takes to travel a distance is calculated like this:
Time = Distance / Speed
The harmonic weighted average is (1+5+2)/(1/10 + 5/30 + 2/50)
becomes 8/(23/75)
equals approx. 26.09 mph.
Weighted harmonic average formula in cell F4:
The formula in cell F4 returns approx. 26.09 which matches the calculated value we did above.
Explaining formula
Step 1 - Add distances
The SUM function allows you to add numerical values, the function returns the sum in the cell it is entered in. The SUM function is cleverly designed to ignore text and boolean values, adding only numbers.
Function syntax: SUM(number1, [number2], ...)
SUM(C3:E3) becomes SUM({1,5,2}) and returns 8.
Step 2 - Divide distance with speed
The division character lets you calculate a ratio based on a numerator and denominator..
C3:E3/C4:E4 becomes {1,5,2}/{10,30,50} and returns {0.1,0.166666666666667,0.04}
Step 3 - Add ratios and return a total
SUM(C3:E3/C4:E4) becomes SUM({0.1,0.166666666666667,0.04} and returns 0.306666666666667
Step 4 - Divide total distance by total time
SUM(C3:E3)/SUM(C3:E3/C4:E4)
becomes
8/0.306666666666667
and returns 26.0869565217391
6. Example 3
A manufacturing plant produces electronic components. The production rates (units per hour) are 50 units/hour while producing 275 units, 25 units/hour for 120 units, 10 units/hour for 435 units, and 40 units/hour for 10 units. What is the average production rate, in other words, calculate the weighted harmonic mean of the production rates?
Cell range B16:C20 contains a data table with the following header names: "Production rate (units/hour)" and "Units produced".
Production rate (units/hour) |
Units produced |
50 | 275 |
25 | 120 |
10 | 435 |
40 | 10 |
Formula in cell C22:
The formula in cell C22 calculates the weighted harmonic mean based on the data in B17:C20. The result is approx. 15.54 units/hour.
7. Function not working
When an array or reference argument contains text, logical values, or empty cells, they are disregarded in the calculation, but cells containing the value zero are taken into account. Arguments that are error values or text that cannot be translated into numbers cause errors.
HARMEAN returns the #NUM! error value if any data point ≤ 0
7.1 Troubleshooting the error value
When you encounter an error value in a cell a warning symbol appears, displayed in the image above. Press with mouse on it to see a pop-up menu that lets you get more information about the error.
- The first line describes the error if you press with left mouse button on it.
- The second line opens a pane that explains the error in greater detail.
- The third line takes you to the "Evaluate Formula" tool, a dialog box appears allowing you to examine the formula in greater detail.
- This line lets you ignore the error value meaning the warning icon disappears, however, the error is still in the cell.
- The fifth line lets you edit the formula in the Formula bar.
- The sixth line opens the Excel settings so you can adjust the Error Checking Options.
Here are a few of the most common Excel errors you may encounter.
#NULL error - This error occurs most often if you by mistake use a space character in a formula where it shouldn't be. Excel interprets a space character as an intersection operator. If the ranges don't intersect an #NULL error is returned. The #NULL! error occurs when a formula attempts to calculate the intersection of two ranges that do not actually intersect. This can happen when the wrong range operator is used in the formula, or when the intersection operator (represented by a space character) is used between two ranges that do not overlap. To fix this error double check that the ranges referenced in the formula that use the intersection operator actually have cells in common.
#SPILL error - The #SPILL! error occurs only in version Excel 365 and is caused by a dynamic array being to large, meaning there are cells below and/or to the right that are not empty. This prevents the dynamic array formula expanding into new empty cells.
#DIV/0 error - This error happens if you try to divide a number by 0 (zero) or a value that equates to zero which is not possible mathematically.
#VALUE error - The #VALUE error occurs when a formula has a value that is of the wrong data type. Such as text where a number is expected or when dates are evaluated as text.
#REF error - The #REF error happens when a cell reference is invalid. This can happen if a cell is deleted that is referenced by a formula.
#NAME error - The #NAME error happens if you misspelled a function or a named range.
#NUM error - The #NUM error shows up when you try to use invalid numeric values in formulas, like square root of a negative number.
#N/A error - The #N/A error happens when a value is not available for a formula or found in a given cell range, for example in the VLOOKUP or MATCH functions.
#GETTING_DATA error - The #GETTING_DATA error shows while external sources are loading, this can indicate a delay in fetching the data or that the external source is unavailable right now.
7.2 The formula returns an unexpected value
To understand why a formula returns an unexpected value we need to examine the calculations steps in detail. Luckily, Excel has a tool that Here is how to troubleshoot a formula:
- Select the cell containing the formula you want to examine in detail.
- Go to tab “Formulas” on the ribbon.
- Press with left mouse button on "Evaluate Formula" button. A dialog box appears.
The formula appears in a white field inside the dialog box. Underlined expressions are calculations being processed in the next step. The italicized expression is the most recent result. The buttons at the bottom of the dialog box allows you to evaluate the formula in smaller calculations which you control. - Press with left mouse button on the "Evaluate" button located at the bottom of the dialog box to process the underlined expression.
- Repeat pressing the "Evaluate" button until you have seen all calculations step by step. This allows you to examine the formula in greater detail and hopefully find the culprit.
- Press "Close" button to dismiss the dialog box.
There is also another way to debug formulas using the function key F9. F9 is especially useful if you have a feeling that a specific part of the formula is the issue, this makes it faster than the "Evaluate Formula" tool since you don't need to go through all calculations to find the issue..
- Enter Edit mode: Double-press with left mouse button on the cell or press F2 to enter Edit mode for the formula.
- Select part of the formula: Highlight the specific part of the formula you want to evaluate. You can select and evaluate any part of the formula that could work as a standalone formula.
- Press F9: This will calculate and display the result of just that selected portion.
- Evaluate step-by-step: You can select and evaluate different parts of the formula to see intermediate results.
- Check for errors: This allows you to pinpoint which part of a complex formula may be causing an error.
The image above shows cell reference B3 converted to hard-coded value using the F9 key. The HARMEAN function requires a number larger than or equal to 0 (zero) which is not the case in this example. We have found what is wrong with the formula.
Tips!
- View actual values: Selecting a cell reference and pressing F9 will show the actual values in those cells.
- Exit safely: Press Esc to exit Edit mode without changing the formula. Don't press Enter, as that would replace the formula part with the calculated value.
- Full recalculation: Pressing F9 outside of Edit mode will recalculate all formulas in the workbook.
Remember to be careful not to accidentally overwrite parts of your formula when using F9. Always exit with Esc rather than Enter to preserve the original formula. However, if you make a mistake overwriting the formula it is not the end of the world. You can “undo” the action by pressing keyboard shortcut keys CTRL + z or pressing the “Undo” button
7.3 Other errors
Floating-point arithmetic may give inaccurate results in Excel - Article
Floating-point errors are usually very small, often beyond the 15th decimal place, and in most cases don't affect calculations significantly.
Functions in 'Statistical' category
The HARMEAN function function is one of 73 functions in the 'Statistical' category.
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form