Link to home
Start Free TrialLog in
Avatar of Roberto Madro R.
Roberto Madro R.Flag for United States of America

asked on

Crystal Report Financial

For simplicity sake, let's say I have 2 tables as a data source for this report;

ActiveTable,  customer, invoice date, invoice amount
HistoryTable, customer, invoice date, invoice amount

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.

Your thoughts please.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Roberto Madro R.

ASKER

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?

Thx
Avatar of Mike McCracken
Mike McCracken

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
mlmcc;

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
Does the past table share invoice numbers with the current table?

mlmcc
mlmcc,

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.
Year(CurrentDate) extracts the year from the current date.  This was so I could get the data for last year.

WHat is in the history table?
You could link them on the customeer number and put the history report in the group (customer) footer.

mlmcc
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.

Many Thanks
Can I reopen or go new?
Is the answer not valid, if so I'll reopen.  If you just need to ask a new question then do so.

mlmcc
Sorry for not getting back any faster, and the best way to answer your question is to explain my project better so that you have a better prospective.

****************************
What you have here are two views,

The "ClosedPeriods" view has the following columns;
ccustno (for customer number)
InvoiceMonth
InvoiceYear
PastSales

The "OpenPeriods" view has the following columns;
ccustno
InvoiceMonth
InvoiceYear
CurrentSales
*******************************************

The essences of this project is to capture the sales from both views and display the results in a columnized fashion, for example;

Customer,         June2010,          June2009,       YTD2010,             YTD2009
A100           ,         $2000      ,          $1000     ,        $11233.00,           $10988.00

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
**********************************************************************************************************************

Your thougths please.
Thx
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.

What is wrong?

mlmcc
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
You would filter based on last year and the same date.

mlmcc