Solved

Crystal Report Financial

Posted on 2010-11-29
14
273 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:codedigger
  • 7
  • 7
14 Comments
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
Comment Utility
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))

mlmcc

0
 

Author Comment

by:codedigger
Comment Utility
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
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
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
 

Author Comment

by:codedigger
Comment Utility
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
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
Does the past table share invoice numbers with the current table?

mlmcc
0
 

Author Comment

by:codedigger
Comment Utility
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.
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
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
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:codedigger
Comment Utility
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
0
 

Author Comment

by:codedigger
Comment Utility
Can I reopen or go new?
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
Is the answer not valid, if so I'll reopen.  If you just need to ask a new question then do so.

mlmcc
0
 

Author Comment

by:codedigger
Comment Utility
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
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
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
0
 

Author Comment

by:codedigger
Comment Utility
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
0
 
LVL 100

Expert Comment

by:mlmcc
Comment Utility
You would filter based on last year and the same date.

mlmcc
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now