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
11 9346 zmbd 5,501
Recognized Expert Moderator Expert
<><><><><><><>< ><><><><><><><> <><><<>>
+ Personally, I would put your frequency in terms of months - make your calculations simpler
+ When you get something like this: - PK Place ActionDate Payment Frequencey
-
3 bbbb 2022-01-01 $12,000.00 annual
-
4 bbbb 2022-02-01 $0.00 annual
Is your monthly payment going to equal zero??
+Simple query like this would return your example (here I use Switch() which isn't strictly SQL ... some would have you use a nested IIF() instead... for a small database the impact of the Switch() shouldn't matter - better yet, switch the frequency in terms of months - no need for either function then :)): - SELECT tbl_payments.PK, tbl_payments.Place, tbl_payments.ActionDate
-
, tbl_payments.Payment, tbl_payments.Frequencey
-
, Switch(Left([tbl_payments].[Frequencey],1)="a",12,
-
Left([tbl_payments].[Frequencey],1)="q",3,
-
Left([tbl_payments].[Frequencey],1)="m",1)
-
AS weighting
-
, [Payment]/[weighting]
-
AS MntPym
-
FROM tbl_payments
-
WHERE (((tbl_payments.ActionDate)=#1/1/2022#));
Returning something like: -
PK Place ActionDate Payment Frequency weighting MntPym
-
1 aaaa 2022-01-01 $1,000.00 monthly 1 $1,000.00
-
3 bbbb 2022-01-01 $12,000.00 annual 12 $1,000.00
-
5 cccc 2022-01-01 $4,000.00 quarterly 3 $1,333.33
NeoPa 32,569
Recognized Expert Moderator MVP
Hi Z.
Long Time No See. Welcome back :-)
Unfortunately, the OP has absolutely not thought this through very well. What happens when you have four months of payment on a quarterly basis. Two quarterly payments but no explicit indicator of the number of months passed hence the expected number of payments. This would go south fast as the OP hasn't designed the data well enough to make this possible without extreme handling of the many different possible scenarios.
Easy enough for a human but using strict logic available to SQL, not so much.
I would suggest they throw this away and start again with better consideration of all the factors.
PS. If you don't like a post you've submitted you can simply edit it. Generally no need to delete & resubmit - though that works too of course.
what i am doing is using the data to map out the cash flow in each month. A user enters the payment, the term, the start date, the frequency and it creates the stream of cash flows for that particular item. I then combine multiple items to get the monthly cash flow of the total.
like the following: -
site freq jan22 feb22 march22 apr22 may22 jun22 jul22 aug22 sept22 nov22 dec22 jan23
-
a mon 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000
-
b quart 0 2000 0 0 2000 0 0 2000 0 0 2000 0
-
c annual 0 0 0 5000 0 0 0 0 0 0 0 0
-
i have a function for each frequency and run the terms through a switch when a new site is created (or edited) . From this i can map out the cash flow monthly for hundreds of sites over multiple years based on the terms.
this all works perfectly for my needs.
I dont understand your response. I have a 0 payment in each month of a quarterly stream reflecting the amount owed for that period.
what i was looking for was actually a less precise method of accounting for the the monthly payments by treating the frequencies greater than a month as a monthly payment (5000/12 for each month for site c above)
I could just run the actual terms through again and adjust the payment amount (divide by 12 for annual) and treat it as a monthly payment in a new query. I would reuse the current structure. The reason I asked the question is do not need the whole stream so I didn't want to go through all the calculations. I just need one value for each site.
a 1000
b 2000/3
c 5000/12
for a monthly approximation of the actual cash flow
Go easy, this is the first time I ever used a site like this and I am self taught so I always assume there is an easier way to accomplish something
I see this. I could do that if the payment was the same all the time. I could it with the weighting factor. My problem is the payment changes through time. (say increase 5% every year on the anniversary of the start date for a multiple year stream) So I was counting on using the current payment (or last payment if it was 0 that month for the quarterly payment example) As you can see in my other post, I already used a switch() to generate the cash flow streams to begin with. I just need to hold the "last payment that wasn't zero" and divide it by the weighting factor based on frequency. (12 for annual, 3 for quarterly, 1 (or don't do it) for monthly).
So without re running the cash flows through the switch, i was just looking for a way to hold the last payment as each row may have a payment or a zero.
zmbd 5,501
Recognized Expert Moderator Expert
@jrol:
NeoPa is one of my favorite mentors - I've learned a lot from him over the years, and never fear, we're all about the self taught!
As Neopa pointed out, and I tried to do so with the 01/01 and 02/01 and, what happens here...
From your second post, trying to follow the table... if you have columns for each of your months, then the dataset is not really optimal for what you're trying to do... I'll PM you here in a moment with a link to our insights covering normalization.
@NeoPa :
> It's been a rough couple of years.
> Something went wonky on my end - stupid updates, by the time I figured out what was happening I'd deleted the old message (actually it didn't appear to have posted who-knows)... and the rest is history. :)
> I have the impression that OP's schema may not be 1NF let alone 2NF or better; thus, data set might be a bit cumbersome. I think we would need to see the business model to really decide how to re-organize the data - if that's even feasible.
Thanks for the help. Now if I can figure out where a PM would show up....
zmbd 5,501
Recognized Expert Moderator Expert NeoPa 32,569
Recognized Expert Moderator MVP
Hi Z (and Jrol).
I'm less bashful about splashing the Database Normalisation and Table Structures link everywhere I can :-D This is perfectly acceptable to post in any thread where it may be seen to pertain (Just in case anyone was unclear of the rules and/or playing it cautiously).
@Jrol.
Now you've explained your situation more clearly we can probably help you to find what you're after from your existing data.
Essentially, for every [Place] you're looking for the single record that has a value set for [Payment] and, within that filtered subset, has the maximum (latest) date. The only way I can think of to get that data from this design is to use a SubQuery filter. This is because every [Place] could be using a different date for its last payment.
Try : - SELECT [Place] AS [P], [Date], [Payment], [Frequency]
-
FROM [YourTable]
-
WHERE ([Payment]<>0)
-
AND ([Date]=(SELECT TOP 1
-
[Date]
-
FROM [YourTable]
-
WHERE ([Place]=[P])
-
ORDER BY [Date] DESC))
This is air-SQL as I haven't done something like this for a while so try it out. If it fails then post back with a clear error message & description of exactly what happened.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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
|
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
|
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...
|
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??
| |
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.
|
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.
|
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 :)
|
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.
|
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...
|
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...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |