Home

Pivot Table StDev calculates different value then the STDEV formula

%3CLINGO-SUB%20id%3D%22lingo-sub-922262%22%20slang%3D%22en-US%22%3EPivot%20Table%20StDev%20calculates%20different%20value%20then%20the%20STDEV%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-922262%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20using%20Excel%202013%2015.0.5153.1000%2032-Bit%20and%20a%20pivot%20table%20to%20calculate%20StDev%20and%20compare%20quickly%20to%20the%20StDev%20calculated%20by%20the%20excel%20formulas.%20I%20noticed%20that%20sometimes%20the%20Pivot%20Table%20StDev%20function%20gives%20a%20different%20value%20compared%20to%20the%20StDev%20calculated%20by%20the%20excel%20formula.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhen%20i%20found%20this%20i%20compared%20the%20StDev%20of%20the%20pivot%20table%20with%20every%20existing%20stdev%20formula%20from%20excel%20to%20see%20if%20i%20can%20get%20a%20match%20with%20one%20of%20the%206%20formulas.%20In%20the%20attached%20file%20you%20can%20see%20this%20comparison%20with%20both%20StdDev%20and%20StdDevp%20function%20of%20the%20pivot%20table.%3C%2FP%3E%3CP%3E12%20times%20out%20of%2050%20the%20StDev%20doesn't%20match.%20The%20error%20is%20very%20small%2C%20only%20the%20last%20few%20decimals%20are%20different.%3C%2FP%3E%3CP%3EColumn%20J%20contains%20the%20values%26nbsp%3BStdDev%20and%20StdDevp%20calculated%20by%20the%20pivot%20table%2C%20in%20columns%20K%3AP%20you%20can%20see%20the%20values%20calculated%20by%20the%20excel%20formulas.%20On%20rows%208%2C%2010%2C%2015%2C%2016%2C%2024%20and%2026%20you%20can%20see%20that%20the%20StDev%20value%20from%20the%20pivot%20table%20doesn't%20match%20with%20any%20value%20calculated%20by%20the%20excel%20formulas.%20(Same%20thing%20for%20the%26nbsp%3BStdDevp%20only%20the%20row%20numbers%20are%20different).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20curious%20if%20anybody%20knows%20the%20reason%20for%20this.%20Did%20anybody%20met%20this%20issue%20before%3F%20I%20can't%20find%20anything%20on%20the%20internet%20regarding%20this.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-922262%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Eformula%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Epivot%20table%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Estddev%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Estdev%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-926464%22%20slang%3D%22en-US%22%3ERe%3A%20Pivot%20Table%20StDev%20calculates%20different%20value%20then%20the%20STDEV%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-926464%22%20slang%3D%22en-US%22%3EI%20assume%20this%20is%20caused%20by%20the%20algorithm%20of%20both%20STEDV%20calculations%20being%20slightly%20different%20hence%20causing%20a%20very%20small%20difference%20likely%20caused%20by%20rounding.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-926537%22%20slang%3D%22en-US%22%3ERe%3A%20Pivot%20Table%20StDev%20calculates%20different%20value%20then%20the%20STDEV%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-926537%22%20slang%3D%22en-US%22%3EI'm%20assuming%20the%20same%20thing%2C%20I've%20checked%20many%20settings%20and%20didn't%20found%20anything%20that%20could%20affect%20the%20StDev%20calculated%20by%20the%20pivot%20table.%20In%20the%20attached%20excel%20file%20i%20also%20set%20up%20the%20experiment%20so%20that%20i%20have%20the%20same%20amount%20of%20samples%20(30%20samples)%20for%20each%20%22TestCodeDescription%22.%20I%20though%20that%20maybe%20this%20is%20the%20cause%2C%20but%20it's%20not.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-926541%22%20slang%3D%22en-US%22%3ERe%3A%20Pivot%20Table%20StDev%20calculates%20different%20value%20then%20the%20STDEV%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-926541%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F22322%22%20target%3D%22_blank%22%3E%40Jan%20Karel%20Pieterse%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EI'm%20assuming%20the%20same%20thing%2C%20I've%20checked%20many%20settings%20and%20didn't%20found%20anything%20that%20could%20affect%20the%20StDev%20calculated%20by%20the%20pivot%20table.%20In%20the%20attached%20excel%20file%20i%20also%20set%20up%20the%20experiment%20so%20that%20i%20have%20the%20same%20amount%20of%20samples%20(30%20samples)%20for%20each%20%22TestCodeDescription%22.%20I%20though%20that%20maybe%20this%20is%20the%20cause%2C%20but%20it's%20not%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-927311%22%20slang%3D%22en-US%22%3ERe%3A%20Pivot%20Table%20StDev%20calculates%20different%20value%20then%20the%20STDEV%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-927311%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F430095%22%20target%3D%22_blank%22%3E%40zsoltturkosi%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20magnitude%20of%20the%20errors%20is%20roughly%20what%20I%20would%20expect%2C%20bearing%20in%20mind%20the%20subtraction%20that%20will%20lose%20you%201%20decimal%20place%20and%20the%20summation%20over%2030%20values%20that%20will%20go%20a%20long%20way%20to%20losing%20a%20second.%26nbsp%3B%20I%20tried%20two%20variations%20of%20the%20formula%20for%20a%20sample%20standard%20deviation%20from%20first%20principles%20and%20got%20results%20that%20varied%20slightly%3C%2FP%3E%3CP%3E%3CFONT%3E%3CSTRONG%3E%3D%20SQRT(%20SUM(%20(x%20-%20x%CC%85)%5E2%20)%20%2F%20(n-1)%20)%3C%2FSTRONG%3E%20%3CEM%3E%3D%26nbsp%3B0.2555612135223550%3C%2FEM%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%3E%3CSTRONG%3E%3D%20SQRT(%20(%20SUM(x%5E2)%20-%26nbsp%3B%20n%20*%20x%CC%85%5E2%20)%20%2F%20(n-1)%20)%3C%2FSTRONG%3E%20%3CEM%3E%3D%26nbsp%3B0.2555612135223660%3C%2FEM%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%3EForm%20my%20sample%20of%201%20test%20case%2C%20the%20first%20formula%20matches%20Excel%20and%20the%20second%20matches%20PQ%2C%20where%20%3CSTRONG%3Ex%3C%2FSTRONG%3E%20was%20defined%20to%20be%26nbsp%3B%24B%24662%3A%24B%24691%20and%20%3CSTRONG%3E%3CFONT%3Ex%CC%85%3C%2FFONT%3E%3C%2FSTRONG%3E%20%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3CFONT%3E%3CFONT%3E%3D%20%3C%2FFONT%3E%3CFONT%3ESUM(x)%20%2F%20n%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-942215%22%20slang%3D%22en-US%22%3ERe%3A%20Pivot%20Table%20StDev%20calculates%20different%20value%20then%20the%20STDEV%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-942215%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%2C%20thanks%20for%20these%20tips.%20I%20double%20checked%20your%20calculation%20and%20I've%20got%20the%20same%20values%20for%20range%20%24B%24662%3A%24B%24691.%20However%20when%20i%20try%20this%20formula%20for%20another%20set%20of%2030%20values%20from%20range%20%24B%24182%3A%24B%24211%20i%20get%20the%20following%3A%3C%2FP%3E%3CP%3E%3CSTRONG%3ESQRT(%20SUM(%20(x%20-%20x%CC%85)%5E2%20)%20%2F%20(n-1)%20)%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CEM%3E%3D%200.23754594757494%3CFONT%20color%3D%22%23FF0000%22%3E10%3C%2FFONT%3E%3CBR%20%2F%3E%3C%2FEM%3E%3C%2FP%3E%3CP%3E%3CEM%3E%3CSTRONG%3ESQRT(%20(%20SUM(x%5E2)%20-%26nbsp%3B%20n%20*%20x%CC%85%5E2%20)%20%2F%20(n-1)%20)%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3D%200.23754594757494%3CFONT%20color%3D%22%23FF0000%22%3E60%3C%2FFONT%3E%3CBR%20%2F%3E%3C%2FEM%3E%3C%2FP%3E%3CP%3EThe%20pivot%20table%20calculates%26nbsp%3B%3CEM%3E0.23754594757494%3CFONT%20color%3D%22%23FF0000%22%3E90%3C%2FFONT%3E%3C%2FEM%3E%20for%26nbsp%3B%24B%24182%3A%24B%24211%20so%20we%20have%20no%20match%20here%20with%20either%20of%20the%20formulas.%20Interesting...%3CEM%3E%3CBR%20%2F%3E%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEdit%3A%20i%20think%20this%20calculation%20issue%20is%20related%20to%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice%2Ftroubleshoot%2Fexcel%2Ffloating-point-arithmetic-inaccurate-result%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice%2Ftroubleshoot%2Fexcel%2Ffloating-point-arithmetic-inaccurate-result%3C%2FA%3E.%20Section%20%22Precision%22%20explains%20that%20excel%20has%20a%20max%20precision%20of%2015%20digits.%20Probably%20something%20else%20is%20still%20going%20on%20because%20of%20the%20of%20the%20pivot%20table's%20framework%20which%20further%20modifies%20the%20decimals%2C%20but%20i%20think%20that%20the%20issue%20is%20certainly%20related%20to%20the%20limitation%20explained%20in%20the%20article.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
zsoltturkosi
New Contributor

Hi,

 

I'm using Excel 2013 15.0.5153.1000 32-Bit and a pivot table to calculate StDev and compare quickly to the StDev calculated by the excel formulas. I noticed that sometimes the Pivot Table StDev function gives a different value compared to the StDev calculated by the excel formula.

 

When i found this i compared the StDev of the pivot table with every existing stdev formula from excel to see if i can get a match with one of the 6 formulas. In the attached file you can see this comparison with both StdDev and StdDevp function of the pivot table.

12 times out of 50 the StDev doesn't match. The error is very small, only the last few decimals are different.

Column J contains the values StdDev and StdDevp calculated by the pivot table, in columns K:P you can see the values calculated by the excel formulas. On rows 8, 10, 15, 16, 24 and 26 you can see that the StDev value from the pivot table doesn't match with any value calculated by the excel formulas. (Same thing for the StdDevp only the row numbers are different).

 

I'm curious if anybody knows the reason for this. Did anybody met this issue before? I can't find anything on the internet regarding this.

 

4 Replies
I assume this is caused by the algorithm of both STEDV calculations being slightly different hence causing a very small difference likely caused by rounding.

@Jan Karel Pieterse 

I'm assuming the same thing, I've checked many settings and didn't found anything that could affect the StDev calculated by the pivot table. In the attached excel file i also set up the experiment so that i have the same amount of samples (30 samples) for each "TestCodeDescription". I though that maybe this is the cause, but it's not

@zsoltturkosi 

The magnitude of the errors is roughly what I would expect, bearing in mind the subtraction that will lose you 1 decimal place and the summation over 30 values that will go a long way to losing a second.  I tried two variations of the formula for a sample standard deviation from first principles and got results that varied slightly

= SQRT( SUM( (x - x̅)^2 ) / (n-1) ) = 0.2555612135223550

= SQRT( ( SUM(x^2) -  n * x̅^2 ) / (n-1) ) = 0.2555612135223660

Form my sample of 1 test case, the first formula matches Excel and the second matches PQ, where x was defined to be $B$662:$B$691 and

= SUM(x) / n

 

@Peter Bartholomew 

Hi, thanks for these tips. I double checked your calculation and I've got the same values for range $B$662:$B$691. However when i try this formula for another set of 30 values from range $B$182:$B$211 i get the following:

SQRT( SUM( (x - x̅)^2 ) / (n-1) ) = 0.2375459475749410

SQRT( ( SUM(x^2) -  n * x̅^2 ) / (n-1) ) = 0.2375459475749460

The pivot table calculates 0.2375459475749490 for $B$182:$B$211 so we have no match here with either of the formulas. Interesting...

 

Edit: i think this calculation issue is related to https://docs.microsoft.com/en-us/office/troubleshoot/excel/floating-point-arithmetic-inaccurate-resu.... Section "Precision" explains that excel has a max precision of 15 digits. Probably something else is still going on because of the of the pivot table's framework which further modifies the decimals, but i think that the issue is certainly related to the limitation explained in the article.

 

Related Conversations
Tabs and Dark Mode
cjc2112 in Discussions on
46 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Extentions Synchronization
Deleted in Discussions on
3 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
29 Replies
Security Community Webinars
Valon_Kolica in Security, Privacy & Compliance on
13 Replies