I don't see it in the documentation; is it perhaps part of an existing function I didn't notice, or available in some other way?
As Andrei Tigau mentioned, STDDEV is not supported yet. That said, you need to calculate it in two pass. Assuming you are interested in column x of YourTable,
SELECT SQRT(SUM(POW(x - avg, 2)/(n-1)))
FROM (SELECT AVG(x) AS avg, COUNT(*) AS n FROM YourTable)
CROSS JOIN YourTable;
You may try following one pass solution as well.
SELECT SQRT(s2/(n-1) - POW(s/n, 2))
FROM (
SELECT COUNT(*) AS n, SUM(x) AS s, SUM(x*x) AS s2
FROM YourTable
);
Depending on type, you may have to cast it to double (especially for s2) to avoid overflow. Both will suffer from floating point errors.
This function does not exist in the official documentation that you have send, so probably it still doesn't exist. If you need something like that you should probably calculate the standard deviation by yourself programmaticaly. You have the AVG function that helps you get at least the median value which will be helpful in the calculation of the standard deviation and the COUNT function for the number of entries.
double standardDeviation ; // standard deviation
double sumOfDiffrences = 0;
for ( int i = 0; i < count; i++ ){
sumOfDiffrences = sumOfDiffrences + pow((entry(i)-avg),2); // entry(i) is an entry of the column you want to create the S.D.
}
standardDeviation = sqrt((sumOfDiffrences)/(count-1));
STDDEV is supported since 2020-06-03.
https://cloud.google.com/spanner/docs/release-notes?hl=en#June_03_2020
I have a large spreadsheet with a number of forumlas and they all make complete sense apart from one, which is listed below. Does anyone have any idea what this NORMALDIST calculation is trying to acheive or tell me? It has relevants to HE
=MAX(1,NORMDIST(3,N18,N18/4,TRUE)-NORMDIST(0,N18,N18/4,TRUE) + 2*(NORMDIST(6,N18,N18/4,TRUE)-NORMDIST(3,N18,N18/4,TRUE)) + 3*(NORMDIST(9,N18,N18/4,TRUE)-NORMDIST(6,N18,N18/4,TRUE)) + 4*(NORMDIST(12,N18,N18/4,TRUE)-NORMDIST(9,N18,N18/4,TRUE)) + 5*(NORMDIST(15,N18,N18/4,TRUE)-NORMDIST(12,N18,N18/4,TRUE)) + 6*(NORMDIST(18,N18,N18/4,TRUE)-NORMDIST(15,N18,N18/4,TRUE)) + 7*(NORMDIST(21,N18,N18/4,TRUE)-NORMDIST(18,N18,N18/4,TRUE)) + 8*(NORMDIST(24,N18,N18/4,TRUE)-NORMDIST(21,N18,N18/4,TRUE)) + 9*(NORMDIST(27,N18,N18/4,TRUE)-NORMDIST(24,N18,N18/4,TRUE)) + 10*(NORMDIST(30,N18,N18/4,TRUE)-NORMDIST(27,N18,N18/4,TRUE)) + 11*(NORMDIST(33,N18,N18/4,TRUE)-NORMDIST(30,N18,N18/4,TRUE)) + 12*(NORMDIST(36,N18,N18/4,TRUE)-NORMDIST(33,N18,N18/4,TRUE)) + 13*(NORMDIST(39,N18,N18/4,TRUE)-NORMDIST(36,N18,N18/4,TRUE)) + 14*(NORMDIST(42,N18,N18/4,TRUE)-NORMDIST(39,N18,N18/4,TRUE)) + 15*(NORMDIST(45,N18,N18/4,TRUE)-NORMDIST(42,N18,N18/4,TRUE)) + 16*(NORMDIST(48,N18,N18/4,TRUE)-NORMDIST(45,N18,N18/4,TRUE)) + 17*(NORMDIST(51,N18,N18/4,TRUE)-NORMDIST(48,N18,N18/4,TRUE)) + 18*(NORMDIST(54,N18,N18/4,TRUE)-NORMDIST(51,N18,N18/4,TRUE)) + 19*(NORMDIST(57,N18,N18/4,TRUE)-NORMDIST(54,N18,N18/4,TRUE)) + 20*(NORMDIST(60,N18,N18/4,TRUE)-NORMDIST(57,N18,N18/4,TRUE)) + 21*(NORMDIST(63,N18,N18/4,TRUE)-NORMDIST(60,N18,N18/4,TRUE)) + 22*(NORMDIST(66,N18,N18/4,TRUE)-NORMDIST(63,N18,N18/4,TRUE)) + 23*(NORMDIST(69,N18,N18/4,TRUE)-NORMDIST(66,N18,N18/4,TRUE)))
Strange question I know, but could not think of where else to ask!!!
Cheers
The equation has a series of terms of the form N*[NORMDIST(3N,mu,sigma)-NORMDIST(3N-3,mu,sigma)] where mu is the mean (N18 in the equation), sigma is the standard deviation (N18/4), and with N going from 1 to 23. This appears to be an estimate involving the average of the normal distribution. It would be more rigorous for N to go from minus infinity to plus infinity and it's not clear why this formula truncated the interval to 1..23. Nevertheless, if the person who wrote the equation was calculating the average, then from the properties of the normal distribution you can derive a closed form solution as:
Total of all NORMDIST terms = mu/3 + 1/2
This will be accurate as long as mu (N18) is in the between 0 and 30. If you plug this into the equation you get
=MAX(1,N18/3+0.5)
Hope that helps.
From the docs...
NORMDIST function
Excel for Office 365 Excel for Office 365 for Mac Excel 2019 Excel 2016 More...
Returns the normal distribution for the specified mean and standard deviation. This function has a very wide range of applications in statistics, including hypothesis testing.
Important: This function has been replaced with one or more new functions that may provide improved accuracy and whose names better reflect their usage. Although this function is still available for backward compatibility, you should consider using the new functions from now on, because this function may not be available in future versions of Excel.
For more information about the new function, see NORM.DIST function.
I am trying to translate an Excel sheet to Delphi and stumbled over the Excel INT.
Excel help say's INT rounds down (toward the negative infinity).
The Excel cell is:
C13-(24*INT(C13/24))
Where C13 is initialized at -465.9862462 and calculates as 14.01375378
The best Delphi I can come up with is:
C13 := -465.9862462;
RoundMode := GetRoundMode;// Save current mode
SetRoundMode(rmDown);
C13 := C13 - (24 * (Round(C13 / 24)));
SetRoundMode(RoundMode);// Restore mode
This produces the correct answer but is there a better way to do this?
Delphi has an Int() function too. It is even documented:
http://docwiki.embarcadero.com/Libraries/Tokyo/en/System.Int
That would grossly be the equivalent of the Excel function. It also rounds down, but not towards negative infinity. It rounds down towards 0. So for negative numbers, you would have to subtract 1.0:
function ExcelInt(N: Extended): Extended;
begin
Result := System.Int(N);
if (Result <> N) and (N < 0.0) then
Result := Result - 1.0;
end;
Note:
One might be inclined to use System.Math.Floor, as that rounds down towards negative infinity already, but that returns an Integer, so for large values, you might get an integer overflow. Note that in Excel, every number is a Double, so its INT() returns a Double too.
The Delphi equivalent is floor:
Rounds variables toward negative infinity.
Short answer: Use System.Math.Floor() function, it is functionally the same as Excel INT() function.
From the Excel documentation for the INT() function we can read that
INT(number) rounds the number argument (a real number) down to the nearest integer.
Ex. INT(8.9) retuns 8, INT(-8.9) returns -9
From the Delphi documentation for the System.Math.Floor() function we can read that Floor() rounds the float type argument toward negative infinity and returns an integer.
Ex. `Floor(2.8) returns 2, Floor(-2.8) returns -3
Testing your function in Excel ( C13-(24*INT(C13/24)) ) and in Delphi ( C13 - (24 * Floor(C13 / 24)) ) both yield the same result of 14.0137538
How to create a Ceiling Function in MS access that behaves the same as the one in Excel?
Since Int() seems to work like Floor(), you can get Ceiling like this:
-Int(-x)
This answer uses VBA for Access, and is derived from http://www.tek-tips.com/faqs.cfm?fid=5031:
Public Function Ceiling(ByVal X As Double, Optional ByVal Factor As Double = 1) As Double
' X is the value you want to round
' Factor is the optional multiple to which you want to round, defaulting to 1
Ceiling = (Int(X / Factor) - (X / Factor - Int(X / Factor) > 0)) * Factor
End Function
Note that this answer is mathematically correct for negative X. See http://en.wikipedia.org/wiki/Floor_and_ceiling_functions#Spreadsheet_software for background.
Thanks, marg, for the answer. For future reference, here is the VBA function that I wrote after importing the Microsoft Excel Object Library:
Public Function Ceiling(Value As Double, Significance As Double) As Double
Ceiling = Excel.WorksheetFunction.Ceiling(Value, Significance)
End Function
Then in my query, I was trying to calculate billable hours from actual time worked, rounding up to the next quarter hour:
SELECT Ceiling(([WorkTimes]![EndTime]-[WorkTimes]![BeginTime])*24,0.25) AS BillableTime
FROM WorkTimes;
You can add a Reference to the Microsoft Excel Object Library and use Excel.WorksheetFunction.Ceiling
While this question specifically asked for Access here is the answer for VB.NET
Public Function Ceiling(ByVal value As Double, ByVal factor As Double) As Double
Return Math.Ceiling(value / factor) * factor
End Function
And the answer in C#
public double Ceiling(double value, double factor)
{
return Math.Ceiling(value / factor) * factor;
}
I'm posting it here because I needed such a function google sent me to this question but I couldn't find an answer for .Net. I finally figured it out for myself.