printmedia
asked on
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!
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
I'll keep working on it, let me know if there are any suggestions.
ASKER
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})
Looks like the correct way to handle it.
mlmcc
mlmcc
ASKER
Thank you!
ASKER
Here's the Command code:
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?