Averaging rows in a table column

Discussion forum about all things Team Developer 5.x and 6.x
Headcold
United States of America
Posts: 25
Joined: 05 Mar 2018, 16:01
Location: USA

Averaging rows in a table column

Post by Headcold » 11 Dec 2019, 17:02

Does anyone know if there is a visual tool chest option for averaging rows in a column? I need to average the 1st 4 rows and the last 4 rows of a column in a table separately.

Thanks

Dave Rabelink
Founder/Site Admin
Founder/Site Admin
Netherlands
Posts: 2924
Joined: 24 Feb 2017, 09:12
Location: Gouda, The Netherlands

Re: Averaging rows in a table column

Post by Dave Rabelink » 12 Dec 2019, 08:33

On tables, I do not think so.

You can loop the table column and place the values in an array and then use SalArrayAvg to get the average.
Regards,
Dave Rabelink

Image
Articles and information on Team Developer Tips & Tricks Wiki
Download samples, documents and resources from TD Sample Vault
Videos on TDWiki YouTube Channel

User avatar
H3PO4
Germany
Posts: 265
Joined: 10 Mar 2017, 07:53
Location: Rohlstorf, Germany

Re: Averaging rows in a table column

Post by H3PO4 » 12 Dec 2019, 09:26

Hi,

wouldn't SalTblColumnAverage work?

You could give the 1st and last rows an extra ROW_Flag that shows SalTblColumnAverage what to include in the average.

Henning

Headcold
United States of America
Posts: 25
Joined: 05 Mar 2018, 16:01
Location: USA

Re: Averaging rows in a table column

Post by Headcold » 12 Dec 2019, 11:32

Thanks guys

Headcold
United States of America
Posts: 25
Joined: 05 Mar 2018, 16:01
Location: USA

Re: Averaging rows in a table column

Post by Headcold » 18 Dec 2019, 12:53

So I am still having some issues getting this to work. I want this to all happen in real time and not have to have the end user trigger any effect using a button. When i use Sam_validate it seems to work fine until I put the validate_ok at the end then every row is filled with the data from the first row entered. Also while using Sam_Validate without the validate_ok it strips the value I enter out of the last field when i move to the next row. So then i tried using SAM _KillFocus but this appears to ignore the entire while statement all together. If anyone has any advice that would be awesome.


On SAM_Validate
Set nRow = TBL_MinRow
While SalTblFindNextRow( grid1, nRow, 0, 0 )
Call SalTblFetchRow( grid1 ,nRow )
If nRow = 0
Set nRow1 = grid1.test
If nRow = 1
Set nRow2 = grid1.test
If nRow = 2
Set nRow3 = grid1.test
If nRow = 3
Set nRow4 = grid1.test
If nRow = 1
Set dfAvgflex = nRow1
Else If nRow = 2
Set dfAvgflex = (nRow1 + nRow2)/2
Else If nRow = 3
Set dfAvgflex = (nRow1 + nRow2 + nRow3 )/3
Else If nRow = 4
Set dfAvgflex = (nRow1 + nRow2 + nRow3 + nRow4 )/4
Return VALIDATE_Ok

User avatar
H3PO4
Germany
Posts: 265
Joined: 10 Mar 2017, 07:53
Location: Rohlstorf, Germany

Re: Averaging rows in a table column

Post by H3PO4 » 19 Dec 2019, 06:52

Hi,
could you please provide a code example?

Thanks
Henning

Headcold
United States of America
Posts: 25
Joined: 05 Mar 2018, 16:01
Location: USA

Re: Averaging rows in a table column

Post by Headcold » 19 Dec 2019, 11:07

H3PO4 wrote:
19 Dec 2019, 06:52
Hi,
could you please provide a code example?

Thanks
Henning
thank you for taking a moment to look. The collbsbatch column is where I am struggling. As you can see when you enter a a value in each row under that column it gets stripped out. If i add the Validate_ok it just stops after first value. I also have a sam_AnyEdit that fails as well on the calculation part. Maybe there is a better way to allow the values and do the calculations. The dfAvgFlex box is where the calculated value should be happening. I hope that all made sense.

average.zip
You do not have the required permissions to view the files attached to this post.

User avatar
H3PO4
Germany
Posts: 265
Joined: 10 Mar 2017, 07:53
Location: Rohlstorf, Germany

Re: Averaging rows in a table column

Post by H3PO4 » 19 Dec 2019, 13:03

Hi,

I tried to bring some life into your grid.

Unless you have no DataSource, the SalTblFetchNext does not fetch Data into your rows, I commented that.

Henning
average.zip
(converted into apt)
You do not have the required permissions to view the files attached to this post.

Headcold
United States of America
Posts: 25
Joined: 05 Mar 2018, 16:01
Location: USA

Re: Averaging rows in a table column

Post by Headcold » 19 Dec 2019, 13:34

H3PO4 wrote:
19 Dec 2019, 13:03
Hi,

I tried to bring some life into your grid.

Unless you have no DataSource, the SalTblFetchNext does not fetch Data into your rows, I commented that.

Henning

average.zip
(converted into apt)
Thank you for your help. Not quite what I was looking for. The problem i was having had to do with one column. Its all good though i figured it ou shortly t after I posted the example.

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 1 guest