473,386 Members | 1,804 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,386 software developers and data experts.

How to calculate percentage change from previous month?

Hi, I am creating a report which needs to calculate the %change from the previous month. I have tried using a nested query which tries to take the value from the previous month and then the current month to get the % change. The issue is the output is in the wrong place. Any help will be much appreciated.
Thank you

Expand|Select|Wrap|Line Numbers
  1. SELECT [Data Research].[Date of Request] AS [Month], [Data Research].[Number of Requests] AS [Total Requests], [Data Research].[Number of Items Requested] AS [Total Items], [Data Research].[Number added to DCS] AS [Items Found], Format(([Number added to DCS]/[Number of Items Requested])*100,"Fixed") AS [% Found], [Data Research].[DCS Assigned] AS [Number Migrated], [Data Research].[DCS Backlog] AS Backlog, Format(((((Select [Data Research].[DCS Backlog] FROM [Data Research] WHERE Year([Date of Request])* 12 + DatePart("m", [Date of Request]) = Year(Date())* 12 + DatePart("m", Date()) - 1)/[Data Research].[DCS Backlog])-1)*100), "fixed") AS [Backlog % increase/decrease]
  2. FROM [Data Research];
  3.  
Jan 26 '11 #1
5 8481
Rabbit
12,516 Expert Mod 8TB
What do you mean the output is in the wrong place? Just change the place.
Jan 26 '11 #2
For example, I want to calculate the %change from jan to feb, this should go in the feb record, but the way the above query works, it puts the answer in the jan record
Jan 27 '11 #3
Rabbit
12,516 Expert Mod 8TB
Can you post some sample data and the expected results?
Jan 28 '11 #4
Sorry for the delay in replying Rabbit, been put on other projects by management, but now they want me to finish off this one.
Back to your question

Data looks like this
Expand|Select|Wrap|Line Numbers
  1. Date of Request    Number of Requests    Number of Items Requested    Number added to DCS    DCS Backlog    DCS Assigned    Requests added to wishlist
  2. 2010/06    12    45    14            
  3. 2010/07    20    42    18            
  4. 2010/08    21    24    10            
  5. 2010/09    31    41    14            
  6. 2010/10    24    40    14    45    12    
  7. 2010/11    46    80    20    37    28    12
  8. 2010/12    16    28    15    41    10    10
  9. 2011/01    30    61    10    35    17    11
  10. 2011/02    18    24    10    23    21    12
  11.  
I need the output to look like this
Expand|Select|Wrap|Line Numbers
  1. Month    Total Requests    Total Items    Items Found    % Found    Number Migrated    Backlog    Backlog % increase/decrease
  2. 2011/01    30    61    10    16.39    17    35    
  3. 2011/02    18    24    10    41.67    21    23    
  4.  
The Backlog% will be the % difference from Jan to Feb, in the Feb row.
I hope that makes sense, and thank you for your help.
May 25 '11 #5
Rabbit
12,516 Expert Mod 8TB
You'll need to use a subquery to return the prior month's backlog so that you can use it in the calculation. Assuming the formula you're using is (CurrentRowBacklog - PriorMonthBacklog) / PriorMonthBacklog, you will need to use the subquery twice to return the prior month's backlog.
May 25 '11 #6

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

Similar topics

9
by: eddie wang | last post by:
How to convert a month to previous month in a very easy way? For example, I have AUGUST, but I want JULY to return. Thanks. *** Sent via Developersdex http://www.developersdex.com *** Don't...
3
by: Killer | last post by:
How can i calculate the last day of the previous month? Help me,please
5
by: Ray via SQLMonster.com | last post by:
Hi there, See if you can help me with the following: I need to write an SQL code that will return me: The 1st day & the Last day of the Previous Month in the following format...
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...
3
by: tulikapuri | last post by:
Dear Friends, I am using the method to cal. percentage in report but no sucess it gives #Num! instead of a number. I am following the steps as given in help to calculate percentage value on a...
2
by: TB | last post by:
HI, is there a formula(function) you could use to the display the previous month's name in a report. i know there is a function(formula) that returns the previous month's value (ie 4 for the...
10
by: Massimo30 | last post by:
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...
0
by: marlberg | last post by:
Platform: Windows2000, WindowsXP, Windows Vista, etc Language: C#, ASP.NET Pre-compiled Libraries: Enterprise Library 3.0 full I have a requirement to implement in and display in C# and...
14
by: yappy77 | last post by:
I have a query that I need help in writing the expression to calculate the first of the month following the end of previous month. Example: Policy expiration date = between 2/1/11 and 2/28/11...
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?
0
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,...
0
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,...
0
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...

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.