
Re: StDev of sum
Alessandro Saccone Jun 24, 2015 4:12 AM (in response to Olle Fredriksson)I think that the expression doesn't work because Sum and StDev are both aggregation functions, so you have to use stdev as you use sum, not togheter

Re: StDev of sum
Olle Fredriksson Jun 24, 2015 5:06 AM (in response to Alessandro Saccone )I see, so I have to use aggr some way in my expressions?
Could you pls give me an example?


Re: StDev of sum
Steven Grice Jun 24, 2015 5:13 AM (in response to Olle Fredriksson)Use
stdev(ValueList(1,2,3,4))
but instead of 1,2,3,4
can be your Variable but you would need iit to be SUM(...),SUM(...) etc

Re: StDev of sum
Jonathan Dienst Jun 24, 2015 5:14 AM (in response to Olle Fredriksson)Assuming vUB works on its own (ie as expression in the chart =$(vUB) ), then you should be able use an Aggr() like this:
=stdev(Aggr(($(vUB)), dim1, ... )
where dim1, ... is a comma separated list of all the chart/table dimensions

Re: StDev of sum
Olle Fredriksson Jun 24, 2015 5:41 AM (in response to Jonathan Dienst )Closing in i think!
However getting different values when calculating in Excel and QV.
Any idea why? Pls see below, and pls see attached example doc.

dots.qvw 153.5 K

Re: StDev of sum
Steven Grice Jun 24, 2015 6:10 AM (in response to Olle Fredriksson)I take it that qlikview is doing
STdev(Aggr(SUM({<TYPE={'A'}>}Amount)+SUM({<TYPE={'B'}>}Amount),Date))
?

Re: StDev of sum
Olle Fredriksson Jun 24, 2015 6:14 AM (in response to Steven Grice )I beleive you are ríght, question is why it differs from the Excel result?
Mystery of the day

Re: StDev of sum
Stefan Wühl Jun 24, 2015 6:15 AM (in response to Olle Fredriksson)Because you are using STDEV.P in Excel.
I believe the QV stdev() function works like STDEV.S in Excel.
For large sample sizes, both Excel functions (STDEV.S and STDEV.P) converge.
You can transform Stdev.S into Stdev.P by calculating something like
Stdev.S * sqrt(N1) / sqrt(N) = Stdev.P
or
Stdev.S = sqrt(N) /sqrt(N1) * Stdev.P
N being your sample size (count of values).

Re: StDev of sum
Olle Fredriksson Jun 24, 2015 8:41 AM (in response to Stefan Wühl )You are right thank you!
However, my reality looks a bit different so unortunately it did not work in my master document.
One of my formulas looks like the below:
(Date<='01/01/2011',
SUM({<[TYPE]= {'A'}>}Amount),
SUM({<[TYPE]= {'B'}>}Amount))Please see below result and attached example document.
Thanks in advance,
Olle

dots2.qvw 153.5 K

Re: StDev of sum
Stefan Wühl Jun 24, 2015 9:22 AM (in response to Olle Fredriksson)To see why this is happening, disable 'suppress zero values' on presentation tab.
You will see that there are actually a lot more records involved in calculating the stdev, many of them zero, which will lead to the large stdev value in QV.
You get the same number as in Excel by creating a Type list box and selecting 'A' (since all your selected date values should result in a Type 'A' aggregation, right?).
Thus your expression:
IF(Date<='01/01/2011',
SUM({<[TYPE]= {'A'}>}Amount),
SUM({<[TYPE]= {'B'}>}Amount))
does not filter the dates to only records belonging to Type 'A'. If you want this, I think you need to rework your expression.

Re: StDev of sum
Stefan Wühl Jun 24, 2015 9:31 AM (in response to Stefan Wühl )Try a variable vUB definition like this:
SUM({<[TYPE]= {'A'}, Date *= {"<=01/01/2011"} >}Amount) +
SUM({<[TYPE]= {'B'}, Date *= {">01/01/2011"} >}Amount)

Re: StDev of sum
Olle Fredriksson Jun 24, 2015 10:07 AM (in response to Stefan Wühl )Nice!
One question, what does the * do?
If it was not for the *, then it would give the same result as with the IFstatement or am I misunderstanding?

Re: StDev of sum
Stefan Wühl Jun 24, 2015 10:12 AM (in response to Olle Fredriksson)No, the intersection operator * is used here to regard the user selections in Date field, if you remove the * operator (try it!), you will get the full Date range evaluated.
You can however simplify my above expression by using an additional Union operator:
SUM({<[TYPE]= {'A'}, Date *= {"<=01/01/2011"} > + <[TYPE]= {'B'}, Date *= {">01/01/2011"} >}Amount)










Re: StDev of sum
Steven Grice Jun 24, 2015 5:15 AM (in response to Olle Fredriksson)Or if you just wanting STdev of all [FLOW TYPE]
stdev(aggr(sum(AMOUNT), [FLOW TYPE]))