MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Apr 29th, 2002, 06:47 AM   #1
Jackeb
Board Regular
 
Join Date: Mar 2002
Posts: 81
Default

Q1. Is there a way to average a range(dnamic) of 6 or 7 numbers with conditions?

Q2 Failing number 1.

I have a list of calculated figures, this list has a large spread and a large scatter. From this i need to filter and trend the points.

The filter should look at a number (call it the primary) and take into account the previous six days (or so) numbers (call these the rolling average) and judge wether the primary number should be there.

simple so far, well relativly, the tricky bit is, once you have assessed the primary and decided that it is not valid, how do you omit it from the rolling average?

The code I have used is in three colums (M,N,O), on with a list of numbers:

Delta Performance
-3.7
-6.5
-10.1
-7.2
-28.6
-4.2
-13.8
-13.1
-15.4
-1.0
-3.9
-8.1
-21.4
-17.2
-18.8
-18.9
-17.2
-10.3
-14.8
-15.6
-21.6
-16.0
-19.6
-13.3
15.7
-18.1
-8.4
-10.8

The next one has this formula, starting from row 8:

=IF(ISERROR(M13),"",IF(IF(AND(M13<(1-Variables!$H$9/100)*O12,M13>(1+Variables!$H$9/100)*O12),M13,FALSE)=FALSE,"*",M13))

where variables!H9 is say 30

and a third column with this code:

=AVERAGE(IF(N13="*",O12,N13),IF(N12="*",O11,N12),IF(N11="*",O10,N11),IF(N10="*",O9,N10),IF(N9="*",O8,N9),IF(N8="*",O7,N8),IF(N7="*",O6,N7),IF(N6="*",O5,N6),IF(N5="*",P4,N5))

starting also in row 8.

as I am sure you can see this is a very cumbersom and difficult code to use. I am trying to make it portable and wish to write it as a function but now I am getting a little over my head, so I thought i would tap the brains on this board to see if you could come up with a simplified version that could be made into a (quick) function as it is not only cumbersome but very, very slow (20000 rows or so)

Hope you can help and any more info just ask!!

Ed

[ This Message was edited by: Jackeb on 2002-04-29 05:48 ]

[ This Message was edited by: Jackeb on 2002-04-29 05:48 ]
Jackeb is offline   Reply With Quote
Old Apr 29th, 2002, 10:35 AM   #2
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default

Hi,

I don't fully understand your problem, but here are some short replies.

Q1: Yes, what are the conditions?

Q2: What determines whether the primary belongs or not?

Bye,
Jay
Jay Petrulis is offline   Reply With Quote
Old Apr 30th, 2002, 01:27 AM   #3
Jackeb
Board Regular
 
Join Date: Mar 2002
Posts: 81
Default

Jay,

sorry it is a difficult one to state, I think that the easiest way to state the problem is to say

I want a colum 'B' averaging the previous six numbers 'A'

ie =average(A1:A6)

the problem is that i need to include a filter in this process, so i suppose it is a two stage process really the averageing and the filtering

For the filter I need to be able to determine wether or not the value for day 2 is < + or > - 30% of the value of day 1, if it is then remove it from calculation if not then include it in the calculation, there are a few refinments that I would like but they are bits around the edge, this is the core of the problem, the example above does it (just) in a worksheet but I need to put it into a function.

VCheers

Ed
Jackeb is offline   Reply With Quote
Old Apr 30th, 2002, 02:22 PM   #4
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default

Hi Ed,

Please test this UDF against your data. It will always include the first cell in the range, and thereafter only include the cells where the change from the previous day is under the threshold value (0.3 in my tests).

It then takes the average of the resulting set.

'---begin VBA---
Function AverageExt(Rng As Range, Threshold As Double) As Double
Dim x, y, z, a, b, c, sumseries

x = Rng.Value
a = Rng.Count
ReDim z(1 To a, 1 To 2)

For y = 1 To a
z(y, 1) = 100 + x(y, 1)

If y = 1 Then
z(y, 2) = z(y, 1)
Else
z(y, 2) = WorksheetFunction.Round(Abs(z(y, 1) - z(y - 1, 1)) / z(y - 1, 1), 4)
End If
Next y

c = a
sumseries = x(1, 1)
For b = 2 To a
If z(b, 2) > Threshold Then
c = c - 1
Else
sumseries = sumseries + x(b, 1)
End If
Next b

AverageExt = sumseries / c
End Function
'---end VBA---

Call as
=AVERAGEEXT(Range,Critical threshold)

Bye,
Jay
Jay Petrulis is offline   Reply With Quote
Old May 1st, 2002, 01:46 AM   #5
Jackeb
Board Regular
 
Join Date: Mar 2002
Posts: 81
Default

Jay, that is great mate.

Looking back i forgot to mention a vital piece of information, the average is going to be used to plot a trend so it must display a colum of numbers, but i have made a few small mods and bar the testing, works great!!

Thanx again

Ed
Jackeb is offline   Reply With Quote
Old May 1st, 2002, 10:03 AM   #6
Jackeb
Board Regular
 
Join Date: Mar 2002
Posts: 81
Default

Jay....

outstanding mate one quick question though.

Why did u use this line..

z(y, 1) = 100 + x(y, 1)

why the +100??

Ed
Jackeb is offline   Reply With Quote
Old May 1st, 2002, 10:11 AM   #7
Jay Petrulis
MrExcel MVP
 
Jay Petrulis's Avatar
 
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
Default

Quote:
On 2002-05-01 09:03, Jackeb wrote:
Jay....

outstanding mate one quick question though.

Why did u use this line..

z(y, 1) = 100 + x(y, 1)

why the +100??

Ed
How am I supposed to know? That was yesterday!!

Actually, as I understood your question, the raw data was percentage change from the previous day. Thus, a value of -15 really meant 1-.15 = .85, or since these were the actual numbers 100%-15% = 85%

This was needed to get the relative change, or else, -1 on day 1 to -1.5 on day 2 would be calculated as a 50% change and would be erroneously excluded.

If I've misunderstood your request, please let me know.

Bye,
Jay

EDIT: By the way, you do not need the rounding in the function.

z(y, 2) = WorksheetFunction.Round(Abs(z(y, 1) - z(y - 1, 1)) / z(y - 1, 1), 4)

could be

z(y, 2) = Abs(z(y, 1) - z(y - 1, 1)) / z(y - 1, 1)

without any real loss for you.


[ This Message was edited by: Jay Petrulis on 2002-05-01 09:14 ]
Jay Petrulis is offline   Reply With Quote
Old May 2nd, 2002, 01:10 AM   #8
Jackeb
Board Regular
 
Join Date: Mar 2002
Posts: 81
Default

Jay that is great,

what do you do mate? You seem to be particually swift around the numbers?

Ed
Jackeb is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 11:22 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes