February 29, 2024

Find Different Sample Standard Deviations with Power Query

Recently I posted a function that helps calculate different averages. One major issue when using the arithmetic mean is that it can be skewed based on outliers. This not only affects average calculations, but also anything derived from it. One example: standard deviations.

I was thinking about this issue and thought: How hard would it be to extend fnMegaAverage() to do sample standard deviations based on these variant means? Not too bad actually!

The Code

Here is the code (link to a gist).

The main part of the code is pretty similar. It calculates the different means, same as fnMegaAverage(). After that, it gets a little tricky. I looped through the incoming list and did the sum of squares calculations for each mean, then divided by the degrees of freedom (number of observations minus one) to calculate the sample standard deviation.

How Do I Use This?

Same as fnMegaAverage()! Just pass in a list. You can either reference a list or you can just reference the table and column like this: table[column]. The table could be a previous step in your applied steps. One trick: If you rename it something simple, like one word without spaces or even PascalCase, it is much, much easier to reference the table then the column.

You may also like