473,385 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Calculating figures from a previous month

Looking for answers and have done a search in books and websites and still can't find the answer:

I am setting up a Market Trend DB on housing figures. I have the following fields in my table:
My objective is to find the percent of change between this month and last month. Easy enough, but how do I set this up? It's not like excel where you can just enter the cell.

Month (Jan,Feb,Mar, etc..)
Year
Market Trend Area
SFR Median Sales Prices
SFR % of Change of Sales Price Formula: (Current Month SFR Median Sales Price -Previous Month SFR Median Sales Price)/(Previous Month SFR Median Sales Price)

How do I set up the formula so that it recognizes which column is the previous month and which is the current month? And how do I have the DB take the year into consideration?

I hope this makes sense.

Thanks any help would be really appreciated.
Aug 27 '07 #1
10 3253
cecil
5
Hi,

I have been scrambling around for solutions to the problem you mention below. I saw you post, but no replies, did you find an answer?

Cecil

Looking for answers and have done a search in books and websites and still can't find the answer:

I am setting up a Market Trend DB on housing figures. I have the following fields in my table:
My objective is to find the percent of change between this month and last month. Easy enough, but how do I set this up? It's not like excel where you can just enter the cell.

Month (Jan,Feb,Mar, etc..)
Year
Market Trend Area
SFR Median Sales Prices
SFR % of Change of Sales Price Formula: (Current Month SFR Median Sales Price -Previous Month SFR Median Sales Price)/(Previous Month SFR Median Sales Price)

How do I set up the formula so that it recognizes which column is the previous month and which is the current month? And how do I have the DB take the year into consideration?

I hope this makes sense.

Thanks any help would be really appreciated.
Aug 27 '07 #2
No still waiting... I'm still searching other sites though -if I find the answer I'll let you know.

Thanks!
Aug 27 '07 #3
FishVal
2,653 Expert 2GB
Looking for answers and have done a search in books and websites and still can't find the answer:

I am setting up a Market Trend DB on housing figures. I have the following fields in my table:
My objective is to find the percent of change between this month and last month. Easy enough, but how do I set this up? It's not like excel where you can just enter the cell.

Month (Jan,Feb,Mar, etc..)
Year
Market Trend Area
SFR Median Sales Prices
SFR % of Change of Sales Price Formula: (Current Month SFR Median Sales Price -Previous Month SFR Median Sales Price)/(Previous Month SFR Median Sales Price)

How do I set up the formula so that it recognizes which column is the previous month and which is the current month? And how do I have the DB take the year into consideration?

I hope this makes sense.

Thanks any help would be really appreciated.
Hi, there.

I have a working solution for you.
First of all you need to reorganize table structure as following.

Tables:

tblMonthSales
keyMonthSaleID Autonumber(Long), PK
keyMonthID Long, FK(tblMonths)
lngYear Long
curSale Currency

tblMonths
keyMonthID Autonumber(Long), PK
txtMonth Text


Having done this you will be able to build the following queries.
Each of them does the same.
So far the queries don't calculate change of sales between January and December of previous year. If you will find this solution acceptable, I'll help you to solve this little problem too. :)
Queries:

qryChangeOfSales
Expand|Select|Wrap|Line Numbers
  1. SELECT tblMonthSales.*, (SELECT t.curSale FROM tblMonthSales AS t WHERE t.keyMonthID=tblMonthSales.keyMonthID-1 AND t.lngYear=tblMonthSales.lngYear) AS curPrevMonthSale, tblMonthSales.curSale/curPrevMonthSale AS ChangeOfSales
  2. FROM tblMonthSales;
  3.  
qryChangeOfSales
Expand|Select|Wrap|Line Numbers
  1. SELECT tblMonthSales.*, tblMonthSales.curSale/tblMonthSales_1.curSale AS ChangeOfSale
  2. FROM tblMonthSales LEFT JOIN tblMonthSales AS tblMonthSales_1 ON (tblMonthSales.keyMonthID = tblMonthSales_1.keyMonthID+1) AND (tblMonthSales.lngYear = tblMonthSales_1.lngYear);
  3.  
Aug 27 '07 #4
Hi There FishVal,

Thank you for the quick response! I'm going to get going on the expert suggestion you provided!

Thanks again! :)
Aug 27 '07 #5
FishVal
2,653 Expert 2GB
Hi There FishVal,

Thank you for the quick response! I'm going to get going on the expert suggestion you provided!

Thanks again! :)
You are welcome and don't hecitate to ask additional questions.
Aug 27 '07 #6
FishVal
2,653 Expert 2GB
BTW, here is SQL for enhanced queries which take care of "Januaries" as well.

qryChangeOfSales
Expand|Select|Wrap|Line Numbers
  1. SELECT tblMonthSales.*, iif(tblMonthSales.keyMonthID=1,(SELECT t.curSale FROM tblMonthSales AS t WHERE t.keyMonthID=12 AND t.lngYear=tblMonthSales.lngYear-1), (SELECT t.curSale FROM tblMonthSales AS t WHERE t.keyMonthID=tblMonthSales.keyMonthID-1 AND t.lngYear=tblMonthSales.lngYear)) AS curPrevMonthSale, tblMonthSales.curSale/curPrevMonthSale AS ChangeOfSales
  2. FROM tblMonthSales;
  3.  
qryChangeOfSales
Expand|Select|Wrap|Line Numbers
  1. SELECT tblMonthSales.*, tblMonthSales.curSale/tblMonthSales_1.curSale AS ChangeOfSale
  2. FROM tblMonthSales LEFT JOIN tblMonthSales AS tblMonthSales_1 ON ((tblMonthSales.keyMonthID=tblMonthSales_1.keyMonthID+1) AND (tblMonthSales.lngYear=tblMonthSales_1.lngYear)) OR ((tblMonthSales.keyMonthID=1) AND (tblMonthSales.lngYear=tblMonthSales_1.lngYear+1));
  3.  
Aug 27 '07 #7
I appreciate the help FishVal. I may contact you again if I expand the query further, but for now I think this is what I was looking for.

:)
Aug 28 '07 #8
FishVal
2,653 Expert 2GB
I appreciate the help FishVal. I may contact you again if I expand the query further, but for now I think this is what I was looking for.

:)
Thanks. You are welcome. :)
Aug 28 '07 #9
Hi FishVal,

-You helped me at the beginning of the week on the below and I have a follow-up question for you:
------------------------------------
I have a working solution for you.
First of all you need to reorganize table structure as following.

Tables:

tblMonthSales
keyMonthSaleID Autonumber(Long), PK
keyMonthID Long, FK(tblMonths)
lngYear Long
curSale Currency

tblMonths
keyMonthID Autonumber(Long), PK
txtMonth Text


Having done this you will be able to build the following queries.
Each of them does the same.
So far the queries don't calculate change of sales between January and December of previous year. If you will find this solution acceptable, I'll help you to solve this little problem too. :)
Queries:

qryChangeOfSales

Code: ( sql )
SELECT tblMonthSales.*, (SELECT t.curSale FROM tblMonthSales AS t WHERE t.keyMonthID=tblMonthSales.keyMonthID-1 AND t.lngYear=tblMonthSales.lngYear) AS curPrevMonthSale, tblMonthSales.curSale/curPrevMonthSale AS ChangeOfSales
FROM tblMonthSales;


qryChangeOfSales

Code: ( sql )
SELECT tblMonthSales.*, tblMonthSales.curSale/tblMonthSales_1.curSale AS ChangeOfSale
FROM tblMonthSales LEFT JOIN tblMonthSales AS tblMonthSales_1 ON (tblMonthSales.keyMonthID = tblMonthSales_1.keyMonthID+1) AND (tblMonthSales.lngYear = tblMonthSales_1.lngYear);
-------------------

New Question:
I ran a simple query to divide 2 additional fields (that was added to tblMonthSales) it returns an answer which I need for an additonal formula. My question is:

1. I need to use that answer to run the same qryChangeofSales which you gave above.
2. How would I write the answer into the query above to give me a calculation again taking into consideration previous and current month?

tblMonthSales:
Field 1:CurInventoryListings
Fields2:Number of Sales

Query: qryInventory
(CurInventoryListings/Number of Sales) =MonthsInventorySupply


Thanks you in advance! :)
Aug 31 '07 #10
FishVal
2,653 Expert 2GB
New Question:
I ran a simple query to divide 2 additional fields (that was added to tblMonthSales) it returns an answer which I need for an additonal formula. My question is:

1. I need to use that answer to run the same qryChangeofSales which you gave above.
2. How would I write the answer into the query above to give me a calculation again taking into consideration previous and current month?

tblMonthSales:
Field 1:CurInventoryListings
Fields2:Number of Sales

Query: qryInventory
(CurInventoryListings/Number of Sales) =MonthsInventorySupply


Thanks you in advance! :)
Hi, Massimo

Sorry. The formula you've posted is somewhat unclear for me.

(CurInventoryListings/Number of Sales) =MonthsInventorySupply

Do you mean [CurInventoryListings] and [Number of Sales] fields supposed to belong to different records (previous/next month) ?

Plz, provide the tables metadata and queries SQL as they are looking so far.

Here is an example of how to post table MetaData :
Table Name=tblStudent
Expand|Select|Wrap|Line Numbers
  1. Field; Type; IndexInfo
  2. StudentID; AutoNumber; PK
  3. Family; String; FK
  4. Name; String
  5. University; String; FK
  6. Mark; Numeric
  7. LastAttendance; Date/Time
Sep 3 '07 #11

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

Similar topics

5
by: Sarah Wang | last post by:
Hello everyone! I want to calculate zprob(the area under the normal curve) with python and I managed to find a function from the internet. But the problem is that the function calculates the...
1
by: Finlay | last post by:
Hi Group I am designing a report that should show a meter reading for each month and the previous meter reading for the previous month. The months are text stored in a field tMonth. The...
7
by: JLM | last post by:
I have a table that has fieldA, fieldB, fieldC. I want fieldC=fieldA-fieldB. simple enough. the next record I want to be able to do the same on the new value of fieldC. I can do this with SAP...
3
by: Paul Mendez | last post by:
Performance_Date SumOfBudget_NOI CurrYTD_BudgetNOI_Total 1/1/2004 $4,184,626.00 ? 2/1/2004 $4,484,710.00 ? 3/1/2004 $4,537,424.00 ? 4/1/2004 ...
2
by: Gustavo G. Rondina | last post by:
It is possible to caclulate every year's easter using simple mathematical operations. Here is a code that does the trick: http://www.brlivre.org/c/easter.c I found the math scheme in an...
5
by: jonm4102 | last post by:
I'm trying to calculate the median of some numerical data. The data can only be found in a query (henceforth query 1) field I previously made, and I would prefer to calculate the median in a new...
5
by: cbalian | last post by:
I am looking for a TSQL code that would calculate a specific date each month that varies based on the following condition: I need the result that would return the date of the Thursday after the...
2
by: ncsthbell | last post by:
I am having problems getting the end date to calculate correctly. I start with Quarter '03/02', (YY/QTR), for this it means it is for the 2nd qtr of 2003. My goal is to get the begin & end dates...
1
by: Del | last post by:
I have a parameter query that requires the user to enter a Start Date: and End Date: and pull data between that date range. I am currently using the following parameter; Select * From mytable...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
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,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.