473,405 Members | 2,415 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,405 software developers and data experts.

Create Ytd And Current Month Columns

4
I am new to this and not to brag, but I'm very impressed at the progress that I have made considering that I have NO formal tutoring on any kind of computer program. It has all be trial and error for me. Anyway, I have created a database for my work. I am satisfied with it except I am stuck on a report. I have a table with:
Fields:
customer id
vendor name
date
invoice
sales

I need to have a report that lists every customer and every vendor with sales columns that show YTD this year, YTD last year, Current Mo this year, and Current Month last year.
I have succeeded in making the different queries but cannot seem to get all of the information in one querie. I did the sub report thing, but it shows the information in "groups" instead of straight across:

i.e.:

Expand|Select|Wrap|Line Numbers
  1. cust 1      vendor 1         ytd
  2. cust 1      vendor 1                     ytd    
  3. cust 1      vendor 1                                 cm
  4. etc.
I want it to look like this:

Expand|Select|Wrap|Line Numbers
  1. cust 1     vendor 1     ytd       ytd        cm       cm
  2.            vendor 2     ytd       ytd        cm       cm
etc.

CAN ANYONE HELP?!?!?!?!
Mar 9 '07 #1
10 4043
NeoPa
32,556 Expert Mod 16PB
Can you post the queries you have already.
Can you explain why there are two ytd values shown?
Mar 10 '07 #2
MMcCarthy
14,534 Expert Mod 8TB
Something like the following should work

Assuming table structure as follows:

VendorName
SalesDate
SalesAmount
Expand|Select|Wrap|Line Numbers
  1. SELECT VendorName, 
  2. Sum(IIf(Year([SalesDate]) = Year(Date()), [SalesAmount],0)) As CurYTD,
  3. Sum(IIf(Year([SalesDate]) = Year(Date())-1, [SalesAmount],0)) As PrevYTD,
  4. Sum(IIf(Year([SalesDate]) = Year(Date()) And Month([SalesDate]) = Month(Date()), [SalesAmount],0)) As CurMth,
  5. Sum(IIf(Year([SalesDate]) = Year(Date())-1 And Month([SalesDate]) = Month(Date()), [SalesAmount],0)) As PrevMth
  6. FROM TableQueryName
  7. GROUP BY VendorName;
  8.  
Mary
Mar 10 '07 #3
NeoPa
32,556 Expert Mod 16PB
Something like the following should work

Assuming table structure as follows:

VendorName
SalesDate
SalesAmount
Expand|Select|Wrap|Line Numbers
  1. SELECT VendorName, 
  2. Sum(IIf(Year([SalesDate]) = Year(Date()), [SalesAmount],0)) As CurYTD,
  3. Sum(IIf(Year([SalesDate]) = Year(Date())-1, [SalesAmount],0)) As PrevYTD,
  4. Sum(IIf(Year([SalesDate]) = Year(Date()) And Month([SalesDate]) = Month(Date()), [SalesAmount],0)) As CurMth,
  5. Sum(IIf(Year([SalesDate]) = Year(Date())-1 And Month([SalesDate]) = Month(Date()), [SalesAmount],0)) As PrevMth
  6. FROM TableQueryName
  7. GROUP BY VendorName;
  8.  
Mary
OK smartie.
So I missed the bit of the explanation where the current & previous stuff was detailed. I was trying to go on the example that was shown which threw me off the scent a bit :D.
Well spotted.
But!
Not to be outdone I went through your SQL with a fine-tooth comb, only to find it was perfect :(
Mar 10 '07 #4
MMcCarthy
14,534 Expert Mod 8TB
OK smartie.
So I missed the bit of the explanation where the current & previous stuff was detailed. I was trying to go on the example that was shown which threw me off the scent a bit :D.
Well spotted.
But!
Not to be outdone I went through your SQL with a fine-tooth comb, only to find it was perfect :(
Well of course it was, when do I ever make mistakes. Shh!
Mar 10 '07 #5
NeoPa
32,556 Expert Mod 16PB
Well of course it was, when do I ever make mistakes. Shh!
Never ask a question you don't know the answer to!
(I suppose you didn't huh? hence the Shh :D)
Mar 11 '07 #6
Marcia
4
Thanks a lot. I'll try this and let you know how it works. Although, it sounds like you are pretty confident.
Mar 13 '07 #7
Marcia
4
[quote=NeoPa]Never ask a question you don't know the answer to!
(I suppose you didn't huh? hence the Shh :D)[/QUOTe
Can I do this in the report controls?
Mar 13 '07 #8
MMcCarthy
14,534 Expert Mod 8TB
Can I do this in the report controls?
You can make this query the Record Source of your report if that's what you mean. I'm not sure what you are asking in your question.

Mary
Mar 13 '07 #9
Marcia
4
You can make this query the Record Source of your report if that's what you mean. I'm not sure what you are asking in your question.

Mary

Got it. It worked great. The only problem is that on the ytd column for previous year, it showed all sales for the entire year instead of just up to the current month. I worked that out. My only other question is...The report is showing customers that have had any sales at any time during the year for last year or this year even if the amounts for the time period is $0.00. How can I illiminate the customers with no sales at all for this time period without affecting the other customers that may have $0.00 values in just some instances?
Mar 14 '07 #10
NeoPa
32,556 Expert Mod 16PB
If you only want those customers that have had 'some' sales in the specified period (regardless of the value of those sales), then an INNER JOIN with the sales data (I don't think we know what/where that is stored) would do you.
If you want only those customers whose sales exceed 0 in the specified period, then you put something like the following in the WHERE clause :
Expand|Select|Wrap|Line Numbers
  1. WHERE Sum([Sales])>0
Mar 14 '07 #11

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

Similar topics

5
by: Ken Fine | last post by:
I want my application to maintain a directory tree based on months and years, e.g.: 2004 January file file file February file
8
by: rong.guo | last post by:
Greetings! I am now doing one type of analysis every month, and wanted to creat table names in a more efficient way. Here is what happens now, everytime I do the analysis, I will create a...
8
by: Donna Sabol | last post by:
First, I should start by saying I am creating a database to be used by some very impatient, non-computer literate people. It needs to be seameless in it's operation from their point of view. I...
1
by: poohnie08 | last post by:
i have a excel spreadsheet showing staff name, date,work hour, ot hour, slot1, slot2, slot3, slot4 and others). The "()" will keep repeating from day 1 until end of month. eg in excel spreadsheet,...
4
by: Abdhul Saleem | last post by:
Hi, I am recieving error ActiveX component can't create object in the following line in the asp page. set ExcelApp = CreateObject("Excel.Application") Previously this code was working fine....
5
by: bruce24444 | last post by:
I have a database which assigns warranty claims to people with a main screen showing number of files assigned to each person. The number assigned shows day, week, month and year numbers so they can...
8
by: Paul H | last post by:
I want to base a form on a crosstab query. The query shows statistics for a user defined period. The column headings will look something like this: ClientID Month01 Month02 Month03 etc.. ...
1
by: TG | last post by:
Hi! I have an application in which I have some checkboxes and depending which ones are checked those columns will show in the datagridview from sql server or no. After that I have 2 buttons:...
1
by: alhomam | last post by:
hi all i have a table with many columns and i need to create a report that the user can select the columns he needs to show in the report. is it possible? thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...
0
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,...

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.