Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does anyone know if/how ArrayAvg ca 1

Status
Not open for further replies.

mikecon

IS-IT--Management
Jun 14, 2001
8
US
Does anyone know if/how ArrayAvg can be made to average the values in just a single column of a 2-d array?

Thanx,
mc
 
Hey mc,

Unfortunately, the built in array functions only work on single dimension arrays. You may be able to find a custom tag that does this from the Allaire Tag gallery though.

If you can't find a custom tag, my only suggestion would be to loop through your two dimensional array and copy the values to a single dimension array and then use the array average function on it.

Hope this helps,
GJ
 
Thanx GJ. Actually, it's funny -- I can act on any _row_ (e.g. ArrayAvg(MyArray[1]) or ArrayAvg(MyArray[2]) works) but could see no way to address the columns. I was thinking I could build the array 'sideways' or 'pivot' (rebuild) the existing one and use the 'row' references above on my former 'columns'. Ever hear of such trickanery? Thanx again for the feedback.

mc
 
Hey mc,

I've never heard of anyone doing that so that's cool to know you can make them work on the rows. I would just rebuild the arrays and use your rows the way you described. Are you using CF 4.5? I'm wondering if this is something that was changed in 4.5.

Take care,
GJ
 
GJ -- It definitely works. I remade the array like this:

<CFSET Days_Array = ArrayNew(2)>

<CFSET Sales_Admin_Col = 1>
<CFSET Credit_col = 2>
<CFSET Provisioning_Admin_Col = 3>

...

<CFLOOP QUERY=&quot;MyQuery&quot;>

<CFSET Days_Array[Sales_Admin_Col][CurrentRow]=#Sales_Admin_days#>
<CFSET Days_Array[Credit_Col][CurrentRow]=#Credit_days#>
<CFSET Days_Array[Provisioning_Admin_Col][CurrentRow]=#Provisioning_Admin_days#>

</CFLOOP>

...

And then stuff like this works:

...

#ArrayAvg(Days_Array[Sales_Admin_Col])#
#ArraySum(Days_Array[Credit_Col])#

BTW, We're using 4.5.1. But, this is not documented -- book says, &quot;Syntax ArrayAvg(array)&quot;.

Do _I_ get a 'helpful tip smiley', now? ;->

Best regards,
mc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top