Summing a calculated control in Access continuous form - ms-access

I have a continuous form with two fields, weight and rate. For each record, I would like to find (weight/sum of all weights)*rate, and then sum these all up. I can get as far as putting a TotalWeight control in the footer, and the calculated control for each record displaying right. But then when I try to do the final sum in another footer control it gives me an #Error, and the calculated control says #Type. What am I doing wrong?

Aggregate functions must reference fields in RecordSource, not textboxes. Options:
do arithmetic calculation in a query that is form RecordSource then use that constructed field in aggregate function in textbox
repeat the entire arithmetic calculation in aggregate function

Related

MS Access Sum #Error

I have an access form and subform that i created using a query. Then, through design view, I created a text box, and entered a rather long nested iif that referred to other fields in the subform.
Now, I want to use the SUM function to add up the values (results of iff) in the created text boxes, each which have different values. I have tried everything I can think of, but it always comes up with #Error! no matter what I do.
Sometimes when I added more than one Function type in a query, it crash what I need to do first is for example create the iff clause to mark or create a new field and put a text like "YES".
then in other query apply the sum on the fields that matches with "YES".
Try by separate it.

MS Access: How can I average a list of quantities on a report where the quantities are not zero?

I have a report. This reports returns a lot of rows. One of the columns is qty_req (quantity required). I need to AVG() this column and put the value of the average at the bottom of the report. The problem is that sometimes some rows have a zero in this column. I want the average to exclude any rows where there is a zero. How can I accomplish this?
What I've tried: I tried using DAvg in the query but it made the query time enormous.
Avg() ignores Null values. So you can use an IIf() expression to swap Null for your zero values, and then base the Avg() on that IIf() expression.
Here is the Control Source for a text box in my report's footer:
=Avg(IIf([gainOrLoss]=0, Null, [gainOrLoss]))
gainOrLoss is a field in the report's Record Source. And the text box displays the average of all those values which are neither zero nor Null.
Well then you can't use a calculated SUM() or AVG() field, simple as that.
These functions always use all rows in the report.
You need DSum() or DAvg() to calculate it separately.
If that's too slow, you need to tackle this problem.

Using SSRS reportitems to create percentage

I have two textboxes, part of a larger matrix, which calculate values based on summing lookups, with filter criteria.
I want to take the figures from each of them, divide one by the other and create a percentage, which will be used in a text string elsewhere in the report.
I can get the individual figures in the header for the relevant page (not ideal, should be in the body of the report) by referencing the report items in the matrix, however when I try to use both I get an error informing me of an apparently arbitrary restriction that 'An expression in a page header or footer can refer to only one report item'.
Attempting to do the calculation with report variables by passing the reportitems and then calculating gives the even less coherent error 'The Variable(blah) value expression used for the language of 'body' refers to a report item. Variable values cannot be used in report language expressions'.
Is there an easy way to do this without adding any extra cells to my original matrix? It seems like there is not much point having variables if you then have to add hidden textboxes in order to store your values.
try doing all your calculations in sql itself and refer the fields in SSRS. i faced a similar issue recently and this is how i did.
Else try using VB code to do the calculations.

SSRS first function automatically added

I'm using SSRS in SQL Server 2008 with Report Builder 3.0 and was wondering, when I add a field on my report from a dataset, why does it automatically add the First() function to it ?
Instead of adding [Field] in a text box, it adds =First(Fields!Field, "Dataset")
Datasets are assumed to always be multiple rows (even though that may not always be the case). So when you drag a field to a report object that isn't meant for multiple rows - such as a textbox - SSRS needs to use an aggregate function of some sort, so that if multiple rows do come back from the dataset, the report doesn't break (since that textbox isn't made to automatically repeat itself for every row).
FIRST is chosen simply because it's least destructive; it could just as easily be SUM, AVG, or any other aggregate function.

Access 2007 running subtraction?

I know access has a running addition. but how can i possibly do a running subtraction on a report? I've exhausted all my outlets and I cannot figure it out.
You'll need to have several hidden controls.
First, in the report's header, use a DSum() to get the total of all your records. That would be a control with a ControlSource something like this:
=DSum("Price","tblInventory")
You may want to provide the third argument for that, which would be a WHERE clause (without the WHERE).
Name that control something like txtTotal.
Now, drop two unbound controls on the detail of your report. Make the first one's ControlSource the field you're totalling and set its Running Sum property appropriately (Over All or Over Group, depending on how your report is set up). Name this control something like txtRunningSum, and set its .Visible property to FALSE.
Now, in the last control, assign this ControlSource:
=[txtTotal]-[txtRunningSum]
That should do the trick -- you'll have a control that subtracts the running sum from the overal total and gives you a descending running sum.
As an alternative, consider simply multiplying your value by -1 and continue to use normal running sum methods...