Group By Year, Month, Week, Day Dynamically in Crystal Reports - crystal-reports

This must be simple, yet I can't seem to find an answer.
I have a simple Query:
SELECT InvoiceTotal, InvoiceDate, InvoiceNoUnit from InvoiceLineItem
Which I want to display in Crystal Reports from my App. Rather than build many reports, I want to be able to have the user change a parameter that allows the resulting report to be grouped by date, based on the level of granularity selected by the user.
EG: I want the user to be able to select "By Month" and the report is grouped by Month (with corresponding Chart displayed by month. Then the user runs the report "by week" and the report changes to group by week.
I want them to select this in my app, and for me to pass a parameter to CR to change the grouping.
Any suggestions?

You can create a parameter where the user selects "Year", "Month", "Day" etc.
From there, you can create a formula that specifies the grouping based on the parameter above, and then create a Grouping in the report that uses this formula to group by.
I don't have Crystal Reports handy, but the formula could look something like this:
IF #UserDefinedGrouping = "Year" THEN
DATEPART(yyyy, {Table.InvoiceDate})
ELSEIF #UserDefinedGrouping = "Month" THEN
DATEPART(m, {Table.InvoiceDate})
ELSEIF #UserDefinedGrouping = "Quarter" THEN
DATEPART(q, {Table.InvoiceDate})
' etc...

Related

Crystal Reports: How to Use a Main Report Parameter within the Select Expert of the Subreport

Thanks for any ideas. The goal here is to show, within a subreport, YTD Sales figures. I'm struggling to successfully create the formula that will allow me to do this.
The user will input 2 values to the main report:
Fiscal Period
Fiscal Year
In the main report, I show sales for the matching fiscal period & fiscal year. That's working fine. But in the subreport, I want to show the sales for the SAME Fiscal year as given in the main report parameter, but for any fiscal period <= the Fiscal Period provided in the main report.
I've attempted to create a parameter in the subreport (YTDSalesFP) and then reference that within the select expert (eg {vSalesTYLY.Fiscal Period} <= {?YTDSalesFP} ) . After I do that, I'm struggling with the "Change Subreport links" dialog on the Main report. After all, I don't want to pass an existing column value to the subreport parameter ?YTDSalesFP} - I just want to use whatever value the user provided, and silently pass it through to the subreport parameter.
Is this possible?
What other routes would you try?

Crystal Reports Greater than or equal to parameter

I am relatively new to Crystal Reports, I have created the report which is all working fine put I want to added to parameters. The first is Customer where the user selects or Customer they want to run the report on, which is working fine.
The second is Delivery date which is what I am stuck on. I want to create a report parameter so that when the user selects the delivery date that it shows all results from the selected date to the current date.
For example:
User selects 01/01/2014 for Customer X : the query should return all deliveries from 01/01/2014 to the current date for customer X.
Can anyone help?
Thanks in advance
Try this:
Create a Parameter Start Date with date datatype and in record selection formula write below code:
Assuming you have a date field in database:
tablename.date>={?Start Date} and tablename.date<CurrentDate

Crystal Reports Filter by Most Recent Date of Field

I have a report I am creating through an ODBC connection. The report includes several invoices, where each invoice has several products. There is also a table which contains all the historical price changes for each product (field: unit-price). Currently there are duplicate product records being pulled, one for each time there was a price change. Therefore, I need to filter my data so that only the most recent unit-price is shown (date field: effective-date). How can I do this via the "Select Expert?"
In short, show the product's unit-price for the most recent effective-date.
Thank you!
You'll need to create a sql-expression field to get the most-recent effective date, then use this field in the record-selection formula.
// {%MAX_EFFECTIVE_DATE}
// most-likely you'll need to alias the table in the main report for this to work
(
SELECT Max(effective_date)
FROM price_history
WHERE product_id = price_history_alias.product_id
)
Record-selection formula:
{price_history_alias.effective_date}={%MAX_EFFECTIVE_DATE}
Instead of doing it in select expert. group by effective date and set the ordering as Descending.

Create a chart using the records of certain type grouped by month, with a moving balance

I am trying to create a chart (bar or line) in crystal from one table in my database (Sage CRM).
The records are as follows
CustomerId Date Invoice Amount
1234 3/4/2013 Cust Invoice 3322.00
1234 3/4/2013 Payment 2445.00
1234 4/5/2013 A/c transaction 322.00
1234 5/6/2013 interest 32.00
1234 6/6/2013 payment 643.00
So I would like to have a report that meets the following criteria
Only records for the last 12 months grouped in month
Only invoice types of payment, invoice and interest
A moving balance that calculates all the invoice amounts ie
(when displaying the information for July 2012, the moving balance will be the total of all invoices prior to this date.
Without this field I can create the chart no problem using select expert but I am not sure now what to do)
Should I use a cross tab? if so how will I do the selection to only show the invoices I want and the the date range I want?
After spending almost a week on this problem, with a lot of help from an expert I have finally got a solution.
In order to create a amount that is the sum of all records for a company, month and invoice type since the beginning of time, while only displaying records for the last year, I have created a SQL command
Select
//All of the fields for the report,
movingBalance.Amount
from myInvoiceTable as mit
<join to any other tables for the report>
left join (
select customerID, sum(amount) as Amount
from myInvoiceTable
where Record_Type in ('Payment', 'Invoice','Interest')
and Date < {?Report Start Date}
group by customerID) movingBalance
on mit.customerID = movingBalance.customerID
where mit.RecordType in ('Payment', 'Invoice','Interest')
and mit.Date >= {?Report Start Date}
and mit.Date <= {?Report End Date}
There are a couple of tricks to using commands:
For performance reasons you generally want to include ALL of the data for the report in a single command. Avoid joining multiple commands or joining one or more tables to a command.
Filter the data in the command, NOT in the Select Expert in the report.
Create any parameters in the Command Editor, not in the main report. Parameters created in the report won't work in the Command Editor.
This has done the trick.
Create Date Parameters in the report to filter out the records at the time of fetching now when you run the report you have left with the data you need.
Now you can manuplate the data inside report using formula fields.
Accoding to me writing stored procedures is a bit hectic task as you can manuplate the data inside the report. I don't have any intentions to disrespect anyone opinions but frankly its my opinion.
In that case Rachsherry I would recommend the following.
For criteria parts 1 & 2 I think instead of using stored procs, it may be easier for you to use a formula.
For invoices right click the invoice field, then "Format Field" in the common tab next to the Suppress option there is a formula button, enter the following...
IF {YourInvoiceField} IN ["Payment", "Invoice", "Interest] THEN FALSE ELSE TRUE
For your date requirement you need to use a selection formula... The code for that should look something like this
{YourDateHere} > DateAdd ("yyyy", -1, CurrentDate) AND {YourDateHere} < CurrentDate
The above code basically looks at dates between the day the report is run, and exactly a year before.
For your moving balance, you should be able to achive that with the guide here
Edit - An alternative to this is to use parameter fields (Which I don't personally like) it just means having to input the parameters every time the report is refreshed, they are self explanatory but you can find a guide here

Crystal Reports: get access to linked elements in selection formula

I'm making a report using Crystal Reports 2008 and Peachtree database. Report should display customers who didn't place orders in a last 30 days. I already figured out how to link two tables in CR with left outer join. But I wasn't able to find how that linking can be used in formulas, such as selection formula. What I am trying to achieve is to get date of last placed order for current customer and use this information to determine if customer should be displayed or not.
What is the right approach to solving this problem?
Assuming your data is setup properly and adding 'customer' and 'last order date' to the details section shows you everything, then you can just add conditional formatting formula for the suppress property of the section when 'data date - last order date < 30', leaving you only showing records where last order date is more than 30 days.