Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Stdev

Hi,

Can anybody help me with the Stdev function. I can't get it to work.

Simple case with question asked how many travels (0, 1, 2 or 3) a year a family undertakes. 200 families answered:

Travels, Families

0, 50

1, 80

2, 60

3, 10

Stdev(Aggr(Sum(Travels), Families)) gives me 1.29. It should be approx. 0.85.

Any help?, Zach

1 Solution

Accepted Solutions
hic
Former Employee
Former Employee

If you load the data using the following script, you will recreate the raw data and the stdev (and average and all other statistical entities) will be calculated correctly:

Data:

Load * while iterno()<= Families;

Load * inline

[Travels, Families

0, 50

1, 80

2, 60

3, 10];

HIC

View solution in original post

7 Replies
hic
Former Employee
Former Employee

But why do you use the Aggr function? This creates a nested aggregation and you need only a single aggregation. The expression "stdev(Travels)" will give 0.85 as answer.

HIC

Not applicable
Author

Hi, thanks for your reply. If I use stdev(Travels) i still get the 1.29?

hic
Former Employee
Former Employee

If you have the raw data, i.e all 200 records, then stdev will work the way you expect it. But if you calculate it from a table of just four records (the ones in your initial post), then 1.29 is correct.

You can most likely calculate it indirectly from you four records using a formula with weighted values (you need to weight the "travels" number by number of families).

HIC

hic
Former Employee
Former Employee

If you load the data using the following script, you will recreate the raw data and the stdev (and average and all other statistical entities) will be calculated correctly:

Data:

Load * while iterno()<= Families;

Load * inline

[Travels, Families

0, 50

1, 80

2, 60

3, 10];

HIC

Not applicable
Author

Hi Henric,

Very helpfull. I thought that the Stdev function would 'automatically' expand over the two elements. Good to know that I need all the individual records for Stdev to work the way I want it to. I now understand that the 1.29 simply is the standard deviation of 0, 1, 2 and 3 occuring 1 time each.

Thank you.

did
Employee
Employee

Dear HIC,

your approach means that stdev operates correctly only with raw data.
In this very case there should be as many rows as count(Families), i.e. = 200.
What about % numbers? What if my table looks like this:
[Travels, Families
0, 25%
1, 40%
2, 30%
3, 5%];
How many rows my raw table must have?

hic
Former Employee
Former Employee

If you want one row per family, and there are 200 families, then you can use this script:
 
Load 
RowNo() as FamilyNo,
Inline
[Travels, Families
0, 25%
1, 40%
2, 30%
3, 5%]
While IterNo() <= 200 * Families;