I'm running weighted averages on ore grades for mine resource estimates. I got the wtd. avg. to come back correctly, but I only need the results out to 3 decimal places instead of the 15 it spit out.
Values like '1.09237094258859E-02' and '0.180000000000004' and '0.349999999999998' are just unwieldy.
How do I get them down to a only 3 decimal places?
Thanks In Advance,
Brian
8 6636
Thanks ChipR
The average function of my query looks like: - AVG(((Resource.MeasuredTons * Resource.MeasuredGrade1) + (Resource.IndicatedTons * Resource.IndicatedGrade1) + (Resource.InferredTons * Resource.InferredGrade1))/(Resource.MeasuredTons + Resource.IndicatedTons + Resource.InferredTons)) AS Grade1WtdAvg
From the link you posted, it seems that it should be like: - AVG(((Resource.MeasuredTons * Resource.MeasuredGrade1) + (Resource.IndicatedTons * Resource.IndicatedGrade1) + (Resource.InferredTons * Resource.InferredGrade1))/(Resource.MeasuredTons + Resource.IndicatedTons + Resource.InferredTons) [,3]) AS Grade1WtdAvg
I've tried a few variations on the bracketed 3 part and either get a 'syntax(missing operator)' error or 'wrong number of arguments used' error when I drop the brackets completely. Leaving that part off entirely results in an "Overflow" error! Not sure what happened there. All I changed from earlier is the (attempted)addition of the "[3]".
Tomorrow is my last day with this company and I'd like to finish this up.
Try this: - FormatNumber(AVG(((Resource.MeasuredTons * Resource.MeasuredGrade1) + (Resource.IndicatedTons * Resource.IndicatedGrade1) + (Resource.InferredTons * Resource.InferredGrade1))/(Resource.MeasuredTons + Resource.IndicatedTons + Resource.InferredTons)),3) AS Grade1WtdAvg
NeoPa 32,556
Expert Mod 16PB
If you want the result simply for display purposes then the Format(), or FormatNumber(), functions will do fine for you.
If, on the other hand, you need the returned values to be numeric (the named functions return string values), then you will need to use one of the various rounding functions. The choice of which to use would depend on your precise requirements.
Thanks for the replies.
I ended up using:
Round(AVG(((...)), 3) AS ...
I feel kinda silly for not figuring it out on my own as it's not that hard. The last few days have been pretty hectic here. Today is my last day here and I need to get a bunch of summary reports put together for a 70-something geologist/VP.
Another quickie. I need to run this query for 4 ore grades. When I try to do it (even just 2 at a time) in a single large query, I get an "Overflow" error. As a result, I now have 5 queries in total. What causes that error?
NeoPa 32,556
Expert Mod 16PB
That depends on what your values are I expect.
We don't have much info on exactly what you're doing, but I would guess some sort of summing. I'm not sure what type of variable the Avg() and Round() functions take.
If that doesn't help much, tell us what you mean by running multiple ore grades together.
Yeah, it's a kinda convoluted setup. I'll try to explain what I mean. Sorry for the length.
Mine resources are divided up into three categories, depending on economic viability. The three resource categories are: Measured, Indicated, Inferred.
Each metal that is or will/may be mined is graded on one or more of these categories as a percentage of metal contained within an amount(tons) of ore. The ore from the mines in my database contain up to four target metals, usually Copper, Molybdenum, Gold, and Silver.
My weighted average calculations are of the grade of a single metal across the three resource categories. The formula above would give me the weighted average for "Metal1". I also need to run it for Metal2, Metal3, and Metal4. When I try to build a single query to find the weighted averages for more than one "Metal" at a time, I get an "Overflow" error. Ver batim, the message says "Overflow." That's it. It only happens when I try to run the weighted average for more than one metal at a time, or "multiple ore grades."
NeoPa 32,556
Expert Mod 16PB
That explains it well enough in general terms, but it tells me very little about the structure of the data you're working with.
Try to explain the situation in database terms.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: AAVF |
last post by:
Hi
We have a problem with a query.
An Access database links via ODBC to a UNIX server. To speed things, we use
the ODBC to load the relevant tables to the local PC that runs Access so
that...
|
by: Randy Harris |
last post by:
How can I report an average of non zero values?
If the values are:
5, 0, 6, 0, 4
I would like the result 5 (15 / 3), not 3 (15 / 5)
Thanks for any help...
|
by: Scott |
last post by:
In order to give a meaning average value and minimum and maximum values, I
would like to have a formula for a group of data after taking out those
extremes. Can someone share your way to...
|
by: satish mullapudi |
last post by:
Hi,
I am using DB2 v8.2 & jdk 1.4.
1. I have a java program which returns an array which contains 1 to 5
numbers.
The code:
public class ArrayTest
{
public static final int ARRAY_SIZE = 5;...
|
by: assgar |
last post by:
Hi
I need help solving a porblem.
I have a form that displays a checkbox, service code, description
and dropdown with fees on each row.
The fee_money and unit array only returns a...
|
by: John |
last post by:
I run a query in VB that calculates an average and a count. Again in code I
want to grab those 2 values from that query without having to write them
first to a table and read the values from that...
|
by: lagomorphmom |
last post by:
Hi,
Can't seem to find a work around for what I thought would be something easy to do. I have a table that contains 3 columns of date values. The date values most often, but not 100%, include the...
|
by: Toby Gallier |
last post by:
Hello!
I have a form that is calculating averages as follows:
" =(NZ()+Nz()+Nz())/3 "
However I need to now adjust for null values , so for example if
value2 is null I would then need to...
|
by: Hongyu |
last post by:
Hi,
I have a datetime char string returned from ctime_r, and it is in the
format like ""Wed Jun 30 21:49:08 1993\n\0", which has 26 chars
including the last terminate char '\0', and i would...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |