I am trying to calculate the standard deviation of a set of values in PowerBI and I am stuck. There are two columns in a table (days and count). This is a frequency distribution of a transportation lane. Days goes from 1 to 100, count is the number of shipments that took those number of days.
The formula to calculate the standard deviation of a frequency distribution is pretty straight forward: sqrt(sum(fx * (x - avgx)^2))/sum(fx)) But the Dax is giving me a massive headache. Any help would be much appreciated. Thanks.
I took the example from the Standard deviation Wikipedia page as sample data.
Converted to Power BI equivalent and fit your requirement as days and count:
And the measure is created as follows, the tricky part is to make use of the SUMX function. I deliberately break down the intermediate steps with
VAR
to make it more clear.Result:
P.S. Power BI actually has some built-in functions for calculating standard deviation, e.g. STDEVX.P, but it's not that useful in this case. Feel free to check it out though.