How do I calculate the average on an Access report - ms-access

I have been trying to insert data for the average net income I've got into a report but I can't figure out how to do it without it placing the data in all the other rows like in the picture. I just want to place individual text in the boxes underlined without them all saying the same thing

If the net income value is available in your underlying data set and you're using grouping to get the Housing Community row, you should be able to use =AVG([NetIncome]) in the control source of the average net income text box.
If the net income information isn't available in the report's data set and you don't want to add it, you could use a DAvg function in the control source of the average net income text box:
=DAvg("[NetIncomeColumn]", "[TableName]", "[Housing Community] = '" & [Housing Community Control Name] & "'")
It will be more efficient to get the net income data into the report's data set. The DAvg function will perform poorly as the amount of data reported increases.

Related

MS Access Date Grouping is not working in report

I have created a simple Microsoft Access 2007 app of receiving and paying vouchers, everything is working properly but one thing that my mind doesn't solve.
I have created a report template of "Receiving Amount" where I want report be grouped in respect of receiving date. I have added a field named "Receiving Date" in "Group, Sort and Total" and when I generate it, it doesn't group the content in respect of date.
Adjust your Grouping and Sorting to use the expression:
Fix([Receiving Date])
I found the solution.
The reason of not grouping date wise because Access could not understand the date, like Gustav said, format is just for display but actual value is different and Sergey S said "If the field with date contains time. you won't be able to group the report".
Finally, I had to remove time from the date and keep it clear to Access so it can group my report.
=MonthName(DatePart("m",[receiving date])) & " " & Format$([receiving date],"d"", ""yyyy")
Where receiving date is the field name.

How can I correct this code to be able to get a difference in weights for each client?

I am working in MS Access. My end goal is a database report that shows the total amount lost so far for each client, based on the texts they send in daily. I've been able to extract the number from the message, but I need to be able to have a running report each day with how much they've lost since they first texted in. I tried this solution with no success: Access SQL Query: Find the most recent date entry for each employee for each training course
After that, I'v been working with the code from here: https://www.techonthenet.com/access/queries/weight.php. I've tried to write a query that brings up the Last Visit Date, but I keep getting type mismatches with this:
DMax("LogDate","NumberQ","TargetFK=" & TargetFK)
NumberQ is a query, where columns are TargetFK (Short text), FirstName (Short text), LastName (short text), LogDate (Date), Message (short text), and Weight (calculated field).
My question is, what am I doing wrong, and is there a better way to do it?
Since TargetFK is a text field, you need quotations around it:
DMax("LogDate","NumberQ","TargetFK='" & [TargetFK] & "'")

How to make sure that MS Access displays the correct subreport data of the current record?

I have a payslip main report with 3 subreports, all are linked through the employee's serialNumber:
rptPayslipPay -for displaying regular pay
rptPSDeds - for displaying deductions
rptPayslipOpay - for displaying supplementary payments. This
subreport is only showed for few selected employees.
I was able to show the total amounts of the 3 subreports on my main report's page footer. Since my last subreport rptPayslipOpay, may or may not have any data, I am displaying it in a text box named [txtOpay] like this:
=IIf([rptPayslipOPay].[Report].[HasData],[rptPayslipOPay].[Report]![sumOpay],"")
My problem is,the value of [txtOpay] shows even if the page has moved on to another employee, thus displaying the previous employee's supplementary payments to the next employee.
Is there a way to prevent this from happening?
Thank you very much.
You might be able to get it to work by fiddling around with the subreports, but assuming a 1:1 relationship between top-level report and subreport, and assuming serialNumber is a string; instead of your IIf statement, you might consider trying something along the lines of:
=DLookup("sumOpay", [rptPayslipOPay].Report.RecordSource, "serialNumber='" & [serialNumber] & "'")
I'm not sure exactly how your objects are named, but I think this should be close to what you're looking for.
By your description, it sounds like "sumOpay" might be a calculated field in the rptPayslipOPay report. If so, you can use:
=DSum("<field containing data to sum>", [rptPayslipOPay].Report.RecordSource, "serialNumber='" & [serialNumber] & "'")
Granted, these will run more slowly, but this might be an easier way to get it to work.
Another option is to left-join rptPayslipOPay's data from in your top-level query, and sum it.

Running Sum by Date criteria in a query (Duplicate Dates)

I want to obtain a running sum in query. I'm using the following running sum formula
RunningSum: CCur(Nz(DSum("[Debit]","[Debit]","[CustomerID] =" & [CustomerID] & " AND [vDate] < " & [vDate] & "")))
But it is not working. My purpose is to obtain sum of Debit for all smaller than the current date field, something like this,
http://i.stack.imgur.com/0qoO7.jpg
After going through different threads, I could not find any solution for my problem. I don't know that how I can get the sum of older debit amounts if there is duplicate date.
I think the easiest thing will be to just refer to running sums for all the controls you want to add. For example "31 to 60 Days" is text29 on your report. Create a hidden control called, say, R31to60 and set to Running sum over group, then in the footer, put a text box and set the control source to:
=[R31to60]
It will show the last value for the running sum, that is, the total.
In design view, the highlight shows the running sum control and total. The control can be shrunk down and hidden.
In report view you can see the "total" field shows the last value for running sum.

How to structure my query for a MS Access Chart?

This is probably an easy one for a guru here.
I have a datatable of employee results by month structured into the following fields:
Name,Metric,Jan,Feb,Mar,Apr, ...,Dec
When I take this dataset as is, and select it all as an input for a simple column graph in MS Excel, the chart figures out that each series is defined by Name+Metric, the (y-axis) is the defined by the values in Jan-Dec columns, and the columns of the graph are split by date (x-axis).
When I feed this same dataset into MS Access with a simple Select query:
Select Name, Metric, Jan, Feb, Mar... Dec from Results
I need to be able to tell the chart how to use the data. How do I do this?
Also, I know that I could flatten the dataset so the dates are in rows, and then use a Crosstab query for Access to figure it out, but it seems inefficient to condense the data so that Access can just expand it out again. I'm going to assume there is a way to tell the chart somehow how to use the data, which is what I am looking for in an answer here.
Option 1
This is a quick and dirty fix.
Excel essentially is creating 'grouped' categories of Name + Metric via concatenation. A quick and dirty solution is to use the default bar chart and set its Row Source property to:
Select Name & ' ' & Metric, Jan, Feb, Mar... Dec from Results
After that if it still needs adjustment, double click on the chart object from design view and see what chart properties you can mess around with.
Option 2
For more advanced control of the chart layout, select your table Results and mess around with the PivotChart function in Access. This chart can later be added as a subform on another report or form.
side note: you should try to avoid the field name "Name" since it is a reserved word