I'm trying to do the following;
1- Group By Customers
2- Run the report based on "ActiveTable.invoice date" parameter I'm generating
3- Bring out the "ActiveTable.Invoice amount" and the "HistoryTable.invoice amount" side by side.
4- Group on the customer
5- Group on the month
6- Calculate a YTD for current and past year
Now this is a simple view of what I want, the rest is bit testy, because in the "ActiveTable" each customer could have multiple invoices within a month, so even if I group on the "Customer" and "Month", mgmt would still like to see the invoice # when the report is drilled down.
When you say you want the active and history side-by-side, I assume you just want the total for the month or do you want to see the details for a given date?
if you just need to see summaries then i would use a COMMAND for the data source like
SELECT * FROM tblActive WHERE Year({Datefield}) = Year(CurrentDate)
UNION
SELECT * FROM tblHistory WHERE Year({Datefield}) = Year(CurrentDate) AND {DateField} <= Date(Year(CurrentDate), Month(CurrentDate),Day(CurrentDate))
Yes, mlmcc, the object is to SUM the Invoice Amount by Month/Year by Customer, it's the sum that I need to display side-by-side, current year next to last year.
As for your recommendation, I've had some success running a similar one from a TSQL client, but to integrate such logic into Crystal Report requires some dancing (unless you can recommend some moves)
Lastly, how about the YTD for current / past years? any nuggest of wisdom?
With the filter i added you will only have data for current YTd and last YTD
Create a new report
Click to ADD NEW DATA SOURCE
Choose the database connection method
Navigate to the database
Choose ADD COMMAND
Use the SQL I presented above changing to use the proper table and field names
mlmcc
0
ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.
One of a set of tools we're offering as a way to say thank you for being a part of the community.
Please see the attached file for full picture of what I'm after, in a nutshell these are the immediate tables involved with their relevant columns and datatypes, and for extra info I added the relation via the arrows. The information stored in CurrentTable have the following flow/logic, Invoice Number 11233, was for customer ABC123, for the amount of $3000, the customer paid that in chunks, each instance / payment / chunk is recorded separately as follows;
Customer number Invoice number Amount Payment date
ABC123 11233 $500 10/1/2010
ABC123 11233 $1000 10/2/2010
ABC123 11233 $1300 10/3/2010
ABC123 11233 $200 10/4/2010
So to get the total from the “CurrentTable” you’ll have to group on the “InvoiceNumber” on the “CustomerNumber”, then by Month and Year based on “PaymentDate”
The way I was tackling this is that I built separate queries for each table, got the data I want out and spun the query code around and built Views of these tables, as I began to pull from these views, I started questioning that approach as it’s limiting me when it comes to aggregation, summation and the like, so I thought to drop you a line.
Please review and let me know, also, what do you mean by Year(CurrentDate) in the solution you, I must have missed something here, please explain.
Thx YearToYear.xlsx
NO it does not, and that's my dilemma, this was a Foxpro database that was converted to MSSQL by an outside group, no reliable ER, no PK FK structure, just wierd and I'm trying to work with what I got.
I'll take any bone you throw my way at this stage.
Not the kind that ignores valuable feedback, they had me putting out other fires, I'll try your approach mlmcc and see where it takes me, in the meantime I'll accept the solution proposed and revisit at a later time if needed.
The YTD logic aggregates the total sales up to the month of the report was run, in our case here, if I was to run the report today, the YTD2010 will reflect all sales starting December 2009 through December 2010, and from the "ClosedPeriods" it'll be December 2008 through December 2009, my code below gives me everything correctly except the YTD for both open and closed periods.
****************************************************************************************************************
SELECT OpenPeriods.ccustno, OpenPeriods.InvoiceMonth, OpenPeriods.InvoiceYear, OpenPeriods.CurrentSales,
ClosedPeriods.InvoiceMonth AS PriorInvoiceMonth, ClosedPeriods.InvoiceYear AS PriorInvoiceYear, ClosedPeriods.PastSales AS PriorSales,
OpenPeriods.CurrentSales - ClosedPeriods.PastSales AS DifferenceByPeriod, SUM(CASE WHEN (OpenPeriods.InvoiceYear) <= YEAR(GetDate())
THEN (OpenPeriods.CurrentSales) END) AS CurrentYTD, SUM(CASE WHEN (OpenPeriods.InvoiceYear - 1)
= ClosedPeriods.InvoiceYear THEN (ClosedPeriods.PastSales) END) AS PastYTD, CASE WHEN (dbo.ClosedPeriods.PastSales) > 0 AND
(dbo.OpenPeriods.CurrentSales) > 0 THEN ((dbo.ClosedPeriods.PastSales) - (dbo.OpenPeriods.CurrentSales)) / (dbo.ClosedPeriods.PastSales)
* 100 ELSE 0 END AS MonthlyDifference
FROM OpenPeriods INNER JOIN
ClosedPeriods ON OpenPeriods.InvoiceMonth = ClosedPeriods.InvoiceMonth AND OpenPeriods.ccustno = ClosedPeriods.ccustno AND
OpenPeriods.InvoiceYear - 1 = ClosedPeriods.InvoiceYear
GROUP BY OpenPeriods.ccustno, OpenPeriods.InvoiceMonth, OpenPeriods.InvoiceYear, ClosedPeriods.InvoiceMonth, ClosedPeriods.InvoiceYear,
OpenPeriods.CurrentSales, ClosedPeriods.PastSales
**********************************************************************************************************************
What is the start date for the YTD you want to use?
YTD only works on the current year. and it starts at 1 Jan 2010.
If you need the prior years or a different start date, then you will have to use formulas.
That's what I was hoping to get your thoughts on, The Formula for PriorYTD, now I have some idea but only in my head at this time but and I was interested in seeing your approach to such formula
if you just need to see summaries then i would use a COMMAND for the data source like
SELECT * FROM tblActive WHERE Year({Datefield}) = Year(CurrentDate)
UNION
SELECT * FROM tblHistory WHERE Year({Datefield}) = Year(CurrentDate) AND {DateField} <= Date(Year(CurrentDate), Month(CurrentDate),Day(Cur
mlmcc