Los datos expuestos en este blog, son solo de índole informativo. Por favor realiza siempre una copia de seguridad antes de realizar cualquier cambio en tu proyecto.
MS Excel: cómo crear una función media personalizada (excluir valores atípicos de los cálculos)
Este tutorial de Excel explica cómo crear una función de promedio personalizada que excluya los valores atípicos de los cálculos (con capturas de pantalla e instrucciones paso a paso).
Pregunta: En Microsoft Excel, ¿cómo puedo promediar una columna de números, excluyendo una o más celdas atípicas que no deben promediarse?
Por ejemplo, si quisiera promediar los siguientes números, pero excluir 4527 del cálculo del promedio porque es un valor inferior a 5000.
8462, 7153, 4527, 8019, 8310, 8176, 8328, 8383, 7810, 8555, 8950, 6760, 8199
R: Para hacer esto, necesita crear una función personalizada.
Necesitas abrir una hoja de cálculo de Excel. Presione Alt+F11 y cree un nuevo módulo.
Luego pegue la siguiente función en el nuevo módulo:
Function CustomAverage(pRange As Range, pThreshold As Long) As Long Dim LFirstRow As Integer Dim LLastRow As Integer Dim LFirstCol As Integer Dim LLastCol As Integer Dim LCurrentRow As Integer Dim LCurrentCol As Integer Dim LTotal As Double Dim LCount As Integer On Error GoTo Err_Execute 'Determine first and last row to average LFirstRow = pRange.Row LLastRow = LFirstRow + pRange.Rows.Count - 1 'Determine first and last column to average LFirstCol = pRange.Column LLastCol = LFirstCol + pRange.Columns.Count - 1 'Initialize variables LTotal = 0 LCount = 0 'Move through each cell in the range and include in the average ' calculation if the value >= pThreshold For LCurrentCol = LFirstCol To LLastCol For LCurrentRow = LFirstRow To LLastRow If Cells(LCurrentRow, LCurrentCol) >= pThreshold Then LTotal = LTotal + Cells(LCurrentRow, LCurrentCol) LCount = LCount + 1 End If Next Next 'Return the average CustomAverage = LTotal / LCount On Error GoTo 0 Exit Function Err_Execute: CustomAverage = 0 MsgBox "An error occurred while calculating the Custom Average." End Function
Ahora, cuando desee promediar sus valores, puede usar la función CustomAverage de esta manera:
=CustomAverage(A2:A14,5000)
Esto devuelve el promedio de los valores en las celdas A1 a A14, excluyendo cualquier valor por debajo de 5000. Entonces, en este ejemplo, excluiría 4527 del cálculo promedio.