473,751 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding a calculated field from a stored query to a new query

5 New Member
I have a question as to the best way to go about solving a problem. MS Access. I have query with the following fields
place, date, payment, frequency
aaaa, 1/1/2022, 1000, monthly
aaaa, 2/2/2022, 1000, monthly
bbbb, 1/1/2022, 12000, annual
bbbb, 2/1/2022 0 , annual
cccc, 1/1/2022, 4000, quarterly

The result for payment is 0 for any month there is no payment

I am trying to get to a result of what the approximate monthly payment is at any point in time. If the frequency is monthly, the payment is just the payment. However, if the payment is annual, I would like to show its monthly rate (12,000/12 from above)

The result set for any given month would be:
place, date, appoxMonthly
aaaa, 1/1/2022, 1000
bbbb, 1/1/2022, 1000
ccc, 1/1/2022, 1000

I could create a recordset from the old query and create a new query and populate with the new calculated values but i'm wondering if i am missing something easier
Apr 12 '22
11 9354
NeoPa
32,571 Recognized Expert Moderator MVP
I played around some more and came up with a version that is more likely to work as required. The Sub-Query can alternatively be saved as a QueryDef and used by name.
Expand|Select|Wrap|Line Numbers
  1. SELECT [Place], [Date], [Payment], [Frequency]
  2. FROM   [YourTable]
  3.        INNER JOIN
  4.        (SELECT   [Place]
  5.                , Max([Date]) AS [MaxDate]
  6.         FROM     [YourTable]
  7.         WHERE    ([Payment]<>0)
  8.         GROUP BY [Place]) AS [sQ]
  9.   ON   [YourTable].[Place]=[sQ].[Place]
  10.  AND   [YourTable].[Date]=[sQ].[MaxDate]
Apr 15 '22 #11
zmbd
5,501 Recognized Expert Moderator Expert
The only issue I see with Neopa's suggestion relates to my question in post#7 in that:
+ If the dates being stored in record fields as implied in Post#4....
[Field1 - Date 1][Field2 - Date 2][Field3 - Date 3][Field4 - Date 4]
Then the only option I really know of to handle this in Access uses VBA. This happens alot in Worksheets; however, at least then you can use Max() on the row and one (or more) of the lookup functions in a dashboard (I have to do this alot with legacy datasets in the Lab where I work - Excel is not a database and array formulas are a form-of-crazy-uniquely-unto-themselves); however, I digress...

+ Of course, If the dates are being stored in a table column, as inferred in OP, which is what base my first suggestion on; then, of course, Neopa's suggestions are closer to what you are after, combine that with my suggestion in Post#2 to convert your text values for frequency and you should be well on your way.
Apr 15 '22 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2346
by: Norbert Lieckfeldt | last post by:
MS Access 2002 here. I am just trying to set up a simple database for a friend who's an optician. Basically, all clients with address details, date of last eyetest and a drop-down combo box to choose a number of months to the next eyetest (3,6,12,24). I then have a calculated field in the form which works out the date of the next appointment on the basis of the previous two sets of information . All that works . I am now trying to set...
4
3079
by: hi | last post by:
I'm having major problem with multiplications in querys. E.g. Table 1 f1 Single f2 Single f1=1.12 f2=.2345 I create a query with just one field a:f1*f2 and I get
3
53772
by: GL | last post by:
Hi, Is there a way to add a field to an existing table using a query of some sort (without needing to manually add a field to the table). I know how to do it with a make table query, but I have a specific need to only add a new field to a table if possible. Here's a simplified example of what I'm trying to do: I get a file with the following two fields: First Name
10
1437
by: MLH | last post by:
MyLocPhone: Format$(,"(@@@) @@@-@@@@") The above expression is a field in a select query. On one XP box (the dev box, of course). It works fine. On two other XP boxen - it fails saying "Function isn't available in expressions in query expression ..." ==> citing the MyLocPhone: Format$(... as the problem. The query is evaluated on-click of a command button. If it returns records, there are things to be done. I have installed the A97...
3
1589
by: Marina | last post by:
I am using Access 2002. I have a client transactions table with a field for HoursBilled, BillingRate, and AmountBilled. Amount Billed is a caluclation of HoursBilled * BillingRate. I can get it to calculate on the fly in both queries and forms, but need this number to be in the table. Anyone have any ideas??
5
5887
by: Henrik | last post by:
The problem is (using MS Access 2003) I am unable to retrieve long strings (255 chars) from calculated fields through a recordset. The data takes the trip in three phases: 1. A custom public function returns a long string. This works. 2. A query has a calculated field based on the custom function above. This works when the query is run directly.
2
1480
by: CSmith | last post by:
I can't get my query to return results when i set the criteria <="$5000.00" in the calculated field column. There are definitely records in the table that match the criteria ... Please help.
24
3791
by: migi48 | last post by:
Hi! I need help on what criteria should I put in order for my query to display records where Within(fieldname of the calculated field) = Yes (it's a Yes/No format) This is my calculated field expression: Within: IIf((Workdays(,)-1)<=7,-1,0) I only want to see records with the "Yes" or "-1" value :)
1
1135
by: ewylie | last post by:
In access 2010, In a query I want a calculated field that will read a previous record then compare the data in the current record to the previous record or from the current record read the data in the next record and compare.
5
1159
by: Hargo | last post by:
Hi I have a query which calculates the duration of each activity undertaken by a patient by simply deducting the from the - I have called this field within the query What I now need is to Total the field for the week so I can see the number of hours of activities a patient does in a week I have used Between Date1 & Date2 in the Date Field Criteria but have no idea what the new formula or expression would be The query currently...
0
9009
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9591
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9412
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8269
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6819
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6090
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4721
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3330
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2230
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.