1. Wayne Wan
  2. PowerBuilder
  3. Wednesday, 17 March 2021 06:27 AM UTC

hi. Here is a datawindow with two column A and B.

I want to get the result of the standard deviation of column A when B =  2. What's the script?

 

Describe("StDevP(if(B=2, A, 0))") ? 

or 

Set Filter(B=2)

Filter()

Describe("StDevP(A)") ? 

 

thanks a lot!

René Ullrich Accepted Answer Pending Moderation
  1. Wednesday, 17 March 2021 08:42 AM UTC
  2. PowerBuilder
  3. # 1

Hi Wayne,

I guess Describe("StDevP(if(B=2, A, 0))") would get wrong values. So I think the method with Filter could be right.

You can also group by B or by a expression with B if it works for your datawindow. So you can calc the stdevp for a group.

HTH,

René

Comment
  1. Matthew Balent
  2. Thursday, 18 March 2021 00:53 AM UTC
Just a thought... If the data is retrieved from a database you could include the standard deviation as part of the initial retrieve.
  1. Helpful
There are no comments made yet.
Wayne Wan Accepted Answer Pending Moderation
  1. Wednesday, 17 March 2021 09:20 AM UTC
  2. PowerBuilder
  3. # 2

thanks.

I know the first script cant be work. 

but there is some comments in the page of powerbuilder's user helps:

 Not in validation rules or filter expressions You cannot use this or other aggregate functions in validation rules or filter expressions.
Using an aggregate function cancels the effect of setting Retrieve Rows As Needed in the painter. To do the aggregation, a DataWindow object always retrieves all rows.

 

It seems that it can't support filter. :(

Comment
  1. René Ullrich
  2. Wednesday, 17 March 2021 12:25 PM UTC
The comment means that you can't use aggregate functions in a filter expression. Means you can't create a filter like "stdevp(a) > 0".

Your approach should work. Try it.
  1. Helpful
  1. Wayne Wan
  2. Wednesday, 24 March 2021 08:13 AM UTC
It works. Thank you!
  1. Helpful
There are no comments made yet.
Olan Knight Accepted Answer Pending Moderation
  1. Wednesday, 17 March 2021 19:48 PM UTC
  2. PowerBuilder
  3. # 3

1. Create a computed COLUMN in the SQL of your datawindow; call it "std_deviation".

2. In your code, determine the standard deviation.

3. Populate the column "std_deviation".

4. Set your filter to use "std_deviation".

 

Olan

 

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.