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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mlmccCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.