Display records in Crystal Reports based on 2 criterias

Hi all.

I'm trying to create a Crystal Report (2011) that displays the AccountNumber, ProductLine and Sales from myTable based on the following criteria:

(1) SalesDate >= {parameter.StartDate} and SalesDate <= {parameter.EndDate}
(2) The AccountNumber can not have already had a sales for the ProductLine one year before the parameter.StartDate

So if the parameters are: StartDate = 02/01/2018 and EndDate = 02/28/2018
Then the ProductLine must have a SalesDate falls between 02/01/2018 and 02/28/2018 AND can not have a SalesDate fall between 02/01/2017 and 01/31/2018. The table (myTable) contains all sales records for each AccountNumber.

Any idea how I can do this Crystal Reports? This report used to be an Access report that used a couple of queries to get the final records but I'm clueless as to how to do it in Crystal Reports, specifically criteria 2.

Thank you in advance!
printmediaAsked:
Who is Participating?
 
mlmccConnect With a Mentor Commented:
You will have to use a query with a subquery

To do this you will need to use a COMMAND for the data source
Something like this

SELECT CustomerID, Other FIelds
FROM SalesTable 
WHERE  Not CustomerID IN (SELECT st.CustomerID FROM SalesTable st WHERE SalesDate Between '2/1/2017' AND '1/31/2018')
AND SalesDate BETWEEN '2/01/2018' and '2/28/2018'

Open in new window


mlmcc
0
 
printmediaAuthor Commented:
Thank you mlmcc!

Here's the Command code:

SELECT    AccountNumber, AccountName, Zone, MainProductLine, FirstReportedDate,Total_Sale_Amt
FROM         myTable
WHERE     (NOT (PrintMediaID IN
                          (SELECT     A.PrintMediaID
                            FROM          myTableAS A
                            WHERE      (Dist_Report_Date >= DateAdd("yyyy",-1,{?StartDate}) AND Dist_Report_Date < =  DateAdd("d",-1,{?StartDate}))))) AND (Dist_Report_Date >= {?StartDate} AND Dist_Report_Date <={?EndDate})

Open in new window



The Dist_Report_Date is a date field. I have an account that is not appearing on my report when I use the following date parameters: StartDate = 02/01/2018 and EndDate = 02/28/2018
This specific account has a Dist_Report_Date of 02/28/2018 it's not included in the report when it should, it does not have any other Dist_Report_Date between 02/01/2017 and 01/31/2018.

Why doesn't it appear?
0
 
printmediaAuthor Commented:
Actually, it's not a date issue, my mistake. The problem is each MainProductLine must be treated separately so an account could have 3 mainproductlines that fall within the date parameters but the criteria has to be applied to each specific MainProductLine. Instead of the account as a whole, which is what's happening now. So accountnumber 'ABC' could have 3 MainProductLines that fall within the date range: ProductLine1, ProductLine2 and ProductLine3 but ProductLine1 and ProductLine2 fail the subquery criteria, then only ProductLine3 should appear on the report. What's happening now is that nothing will show if at least one of the MainProductLines fail.

I'll keep working on it, let me know if there are any suggestions.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
printmediaAuthor Commented:
Ok. I think I figured it out but I'd like to know if this the correct way to do it, I've looked at some sample data and it's showing the correct records:

SELECT    AccountNumber, AccountName, Zone, MainProductLine, FirstReportedDate,Total_Sale_Amt
FROM         myTable myT
WHERE     (NOT (PrintMediaID IN
                          (SELECT     A.PrintMediaID
                            FROM          myTableAS A
                            WHERE   (A.MainProductLine = myT.MainProductLine) AND   (Dist_Report_Date >= DateAdd("yyyy",-1,{?StartDate}) AND Dist_Report_Date < =  DateAdd("d",-1,{?StartDate}))))) AND (Dist_Report_Date >= {?StartDate} AND Dist_Report_Date <={?EndDate})

Open in new window

0
 
mlmccCommented:
Looks like the correct way to handle it.

mlmcc
0
 
printmediaAuthor Commented:
Thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.