I have a Crystal Report that looks like:
Date | Person | Ticket | Summary
Date | Person | Ticket | Summary
Date | Person | Ticket | Summary
I would like it to look like:
Date
Person | Ticket | Summary
Person | Ticket | Summary
Date
Person | Ticket | Summary
All values are pulled from a MS SQL 2000 database, the application that will ultimately use the report is a VB 6 app that I unfortunately have to support.
Crystal has a function to add a grouping and all you need to do is select your date field into it. You should be able to do this by right-clicking on the date field and selecting the 'group by' option!
JFV has the right answer. The only additional thing to watch for is when adding the group the last drop down on the "Common" tab ("This section will be printed:") sets that you want to group the data by date rather than by hour, week, month year or whatever time period.
If you haven't set this and your datetime field in the database also contains a time part, you may end up with more groups than you anticipated.
If you forgot to set the "This section will be printed:" option, right click on the section part and select "Change Group..."
Related
I am trying to create a report to show our overall quality tending over time by month or quarter (over a span of several years). The main report will show all of our shipments over the specified time period grouped by month/quarter, and the sub report will show all returns entered during that month/quarter that result in scrap or rework.
The issue I am having is linking the sub report to the date group in the main report. After several attempts using different methods, the best I could do is show all returns within the date parameter in every group footer.
This is my first time posting, so I'm not sure what additional info will be needed to assist. Please let me know if there is more needed.
*Edit for additional info
I would like the subreport to show data for each month or quarter in the given time period. So if the date range of the report is for 1/1/2018 - 9/30/2018 and the data is grouped by month, I would like the subreport to show only the data from each month group. General layout below.
January
Shipments
Returns (subreport showing data for January)
February
Shipments
Returns (subreport showing data for February)
*Second edit to add screenshot and more info
I stripped all the parameters from the subreport because I couldn't get any of them to work. The only parameter on the main report is the Date Range that prompts users for a start and end date.
The main report has the shipments in the details section.
Current layout below. If I can get this current issue resolved, I will be adding values passed up from the subreport to calculate the quality rating for each month, then passing them back down to a second subreport to summarize and chart.
Quality Trend Layout
*Third edit for data source and example data
The main and subreports are pulled from tables in our company database.
SQL query used for the main report. Only the "Releases" table is used to show how many and when each part was shipped. DelType=0 is specifying a customer delivery. The date range is defined by a user entered parameter.
Main Report
SELECT
"Releases"."DateComplete",
"Releases"."DelType",
"Releases"."PartNo",
"Releases"."Qty",
"Releases"."JobNo",
"Releases"."PartDesc"
FROM "COMPANY"."dbo"."Releases" "Releases"
WHERE "Releases"."DelType"=0 AND
("Releases"."DateComplete">={ts '2018-01-01 00:00:00'} AND
"Releases"."DateComplete"<{ts '2018-10-01 00:00:00'})
I am trying to use CustReturn.DateEnt as the datetime link to Releases.DateComplete in the main report (not currently linked at a paramter because it didn't work), and only select records that are customer returns resulting in rework, scrap, sort, or repair.
Subreport
SELECT
"CustReturn"."DateEnt",
"CustReturn"."CustRMANo",
"CustReturnDet"."OrigJobNo",
"CustReturnDet"."PartNo",
"CustReturnDet"."QtyReturned",
"CustReturnDet"."QtyToRework",
"CustReturnDet"."QtyToRestock",
"NonConformance"."Disposition",
"NonConformance"."ReturnType",
"CustReturn"."IssueDate",
"NonConformance"."NonConfDate",
"CustReturnDet"."PartDesc"
FROM
("COMPANY"."dbo"."CustReturn" "CustReturn" INNER JOIN "COMPANY"."dbo"."CustReturnDet" "CustReturnDet" ON "CustReturn"."CustRMANo"="CustReturnDet"."CustRMANo")
LEFT OUTER JOIN "COMPANY"."dbo"."NonConformance" "NonConformance" ON "CustReturnDet"."NonConfNo"="NonConformance"."NonConfNo"
WHERE ("NonConformance"."Disposition"='REPAIR' OR
"NonConformance"."Disposition"='REWORK' OR
"NonConformance"."Disposition"='SCRAP' OR
"NonConformance"."Disposition"='SORT') AND
"NonConformance"."ReturnType"='CUSTOMER'
Quality Trend Example Data
First, I want to give a big thanks to Digital.Aaron. Your help in solving this is greatly appreciated.
Your answer was quite close to what I needed. I was still unable to get the subreport to show any data after adding the additional lines to the SQL statement, so I tried something a little different. I made the additional statements into formula fields.
Main Report Field
DATEADD("D", -1*(DATEPART("D",{Releases.DateComplete})-1),{Releases.DateComplete})
Subreport Field
DATEADD("D", -1*(DATEPART("D",{CustReturn.DateEnt})-1),{CustReturn.DateEnt})
I used these fields as the link between the main report and subreport, but still couldn't get the data to show. The issue turned out to be setting them as = to each other in the record select formula of the subreport. I named the formulas DatePeriod
Original Record Select
{#DatePeriod} = {?Pm-#DatePeriod}
Modified Record Select
{#DatePeriod} in Date({?Pm-#DatePeriod})
Once I made the change, everything fell into place.
Thanks again,
Jeff
So it looks like you're grouping on Releases.DateComplete. Let's assume this value is the same for all records associated with a given month. Let's also assume the following (simplified) sample data for Shipments:
ShipmentDate | PartNo | Qty | DateComplete
01/01/2018 | 0001 | 1 | 01/31/2018
01/05/2018 | 0031 | 10 | 01/31/2018
01/31/2018 | A314 | 4 | 01/31/2018
Your Returns data would then need to look something like this:
ReturnDate | PartNo | Qty | DateComplete
01/15/2018 | 0031 | 7 | 01/31/2018
Notice they both have a DateComplete column.
Now in your Crystal Report template, you'll use the DateComplete field from the main report results set as the input to your subreport parameter. Your design layout looks like it would be correct here, as you'll want the subreport to be called in the group footer.
EDIT: So it looks like DateComplete is not the same for all records in a given month. That's fine. We're going to add a column to both the main query and the subreport query that WILL be the same for all records in a given month, and that we can then use to link the records.
Your main query would become:
SELECT
Releases.DateComplete,
Releases.DelType,
Releases.PartNo,
Releases.Qty,
Releases.JobNo,
Releases.PartDesc,
DatePeriod = DATEADD(DAY, -1*(DATEPART(DAY,Releases.DateComplete)-1),Releases.DateComplete)
FROM COMPANY.dbo.Releases Releases
WHERE Releases.DelType=0
AND (Releases.DateComplete>={ts '2018-01-01 00:00:00'} AND Releases.DateComplete<{ts '2018-10-01 00:00:00'})
Your subreport query would then become:
SELECT
CustReturn.DateEnt,
CustReturn.CustRMANo,
CustReturnDet.OrigJobNo,
CustReturnDet.PartNo,
CustReturnDet.QtyReturned,
CustReturnDet.QtyToRework,
CustReturnDet.QtyToRestock,
NonConformance.Disposition,
NonConformance.ReturnType,
CustReturn.IssueDate,
NonConformance.NonConfDate,
CustReturnDet.PartDesc,
DatePeriod = DATEADD(DAY, -1*(DATEPART(DAY,CustReturn.DateEnt)-1),CustReturn.DateEnt)
FROM COMPANY.dbo.CustReturn CustReturn
INNER JOIN COMPANY.dbo.CustReturnDet CustReturnDet ON CustReturn.CustRMANo = CustReturnDet.CustRMANo
LEFT OUTER JOIN COMPANY.dbo.NonConformance NonConformance ON CustReturnDet.NonConfNo = NonConformance.NonConfNo
WHERE NonConformance.ReturnType='CUSTOMER'
AND (
NonConformance.Disposition='REPAIR'
OR NonConformance.Disposition='REWORK'
OR NonConformance.Disposition='SCRAP'
OR NonConformance.Disposition='SORT'
)
DatePeriod will always be the date of the first day of the month. Now we can use this as the Link field between the main report and the subreport. You could also consider making this the field that you Group on, instead of the month value.
using SSRS 2008 R2 here.
I've been able to get a similar layout to work with a regular tablix, where I get each group header to fall on top of each other in the same column by adding a row within that group, however I need to use a Matrix because of a dynamic column (month below). When I try to add another row, it only adds a row where the monthly data starts, not in the headers. So the headers stay in their each column. In trying to keep the example as easy as possible, I'm trying to do something like this (Store theme).
STORE NAME | MONTHS
STATE | SALES
TOWN(S) | SALES
which woudl look something like this in a Matrix
WALMART JAN FEB MARCH etc....
TEXAS | 3000 2000 6000
HOUSTON | 1000 500 2500
AUSTIN | 2000 1500 3500
I've only been able to produce something like this where each group is a seperate column:
STORE | STATE | CITY | JAN | FEB | MAR |
WALMART | TEXAS | HOUSTON | 1000 | 500 | 2500 |
| AUSTIN | 2000 | 1500 | 3500 |
Again, I've been able to get a regular Tablix formatted like this, but a Matrix I'm struggling with. Can anyone help me on how to do this? Thank you in advance!!
It is possible using a tablix/matrix and adding some special grouping settings.
Add a tablix with the City field in Row Groups pane:
Right click the City group, select Add Group / Parent Group. Choose State and set Add a Group Header
Delete the left most column (State column added in the previous step).
Note the group is still present.
Right click the STATE group and add a Parent Group as step 2. In this case choose STORENAME
Again delete the left most column (Store Name column added in the previous step)
You will get the following tablix.
Delete the first row
Set the Fields using the Row Group hierarchy order. STORENAME/STATE/CITY
Right click the first cell in the next column and add a group / Column Group / Parent Group. Choose MONTH in group by.
Delete the first row.
Set SUM(Fields!Sales.Value) in the next cells in the same column.
After these steps you will get a tablix like this in design window.
It should produce:
Let me know if this helps.
I'm going to attempt to word this question without being too confusing.
We have a report we want to show each patient and their insurance. Each of the insurance in the patient's record is number by an Order Number. However, we don't only want to show that; I want to put in certain criteria so that if Insurance A has order number 1 under the Patient ID, show all of this patient's insurance. If the patient does not have Insurance A in Order Number 1, do not show this patient nor any of their information on the report.
In the code below, guarantor is referring to insurance. So order number and guarantor name is what we're focusing on. Here's the code I've put into Section Expert for the Suppress option. What I assume is if it meets the criteria, TRUE will suppress the information, else FALSE will allow the information. However, this is not sufficient as it suppresses all of the other information.
if {billing_guar_order_no_ep.guarantor_order_number} = "1" AND
{billing_guar_order_no_ep.guarantor_name} = "Medicare" then
false
else
true
What I'm assuming is it will need to iterate or loop through every patient and if it finds this information, list ALL of the patient's information and move forward, else suppress and move forward. I hope this makes sense.
Example:
|Patient ID|Order Number|Guarantor Name|
| -------- | ---------- | ------------ |
|1 | 1|Medicare |
|1 | 2|Medicaid |
|2 | 1|Medicaid |
|2 | 2|Medicare |
In the above example, what I want is for the report to show everything from Patient #1 (including all order numbers) and to not even show Patient #2 in the report. However, what's happening is Patient #1 does show up, but only Order Number 1; it suppresses all the other information.
What am I missing?
The query that you want will be an adaptation of this:
select *
from data d
where not exists (
select 1
from data
where pat_id=d.pat_id
and order_id=1
and guarantor_name='Medicaid'
)
The 'Linking Expert' doesn't support this syntax, so you'll need to use a Command instead.
Process:
get the current query by selecting Database | Show SQL Query ...
create a new report
select 'add command' from within the database expert
paste the query, then adapt it
I have a crystal report, it has a group by statement based on two fields
Companyname
Account Type
Now Crystal report work and it does group by "companyname" but it does not group by "account type". I have two types of account, "Regular and Premium". One company has both type of account with us and it pulls on regular and not premium. What do you think is the issue.
I am new to crystal report. I am familiar with SQL Though. The differences that I see is
There is no aggregate function used for any column - in SQL an aggregate field is required to get meaningful result
There are about 10 fields in the report but group by is used only on two fields - in SQL you have to group by all fields if there are more than two fields
The group by fields are in the middle and in end - again in SQL the order of groupby field is important
In this case I am grouping by companyname first and then account status. Any insight will be helpful.
Note that I generated the equivalent SQL statement from Crystal Report. That query was ok except there were not group by statements. I added those and the aggregate column myself and I do get the same result as I am getting in Crystal (but the SQL report is more accurate as it does group by both the fields not just one).
Edit: Example Date. Each company can have multiple account of the same type. I want aggregate on "Company Name" and "AccountType" so that the data is listed as follow.
+----+--------------+-------------+------+
| ID | Company Name | AccountType | Sale |
+----+--------------+-------------+------+
| 1 | ABC | I | 500 |
| 2 | ABC | I | 600 |
| 3 | ABC | O | 1000 |
| 4 | ABC | O | 2000 |
| 5 | ABC | O | 3000 |
| 6 | XYZ | O | 2500 |
| 7 | LMN | O | 3400 |
+----+--------------+-------------+------+
Output I want from the above table is
+--------------+-------------+------+
| Company Name | AccountType | Sale |
+--------------+-------------+------+
| ABC | I | 1100 |
| ABC | O | 6000 |
| XYZ | O | 2500 |
| LMN | O | 3400 |
+--------------+-------------+------+
Update to incorporate comment discussion and revised question:
There are two basic options for resolving this issue:
1) Revise the SQL to perform the desired aggregation.
2) Within Crystal, add two groups, one for the company, then one for the account type.
Before you add groups in crystal, you have several standard sections, including the Report Header, Page Header, Details, Report Footer, and Page Footer.
If you do not perform grouping, each row that is read in the database will be displayed in the details section (technically, the entire details section is repeated for each row).
When you add the first group (Company), Crystal adds a Group Header #1 before the Details section and a Group Header #1 after the Details section.
If you run the report at this point, for each company Crystal will show the Group Header before each group of detail records associated with that company, then will show all of the detail records for that company, and finally, will shown the Group footer for that company.
Typically, the group header is used to display common information for that grouping that does not need to be repeated for each detail record. In this example, we could display the company name and other information related to the company.
Likewise, the group footer is typically used to display summary information for all of detail records displayed within that group.
In this case, we could add an aggregate that would summarize the Sale amount, which would be the total sales for that company, regardless of the account type.
When the second group is added, it will perform sub-grouping on the original group.
When the second group is added, Crystal will place a Group Header #2 below Group Header #1 and above the Details and will place a Group Footer # 2 directly below the details and above the Group Footer #1.
At this point, you have a report format similar to the following:
Group Header #1 (Company)
Group Header #2 (Account Type)
Details (the individual sale records)
Group Footer #2
Group Header #1
In this case, for each company, we want to group the details records by account type. So we can add information that describes the account type, if we want, to the Group Header #2 and we can add aggregates to Group Footer #2 to display totals for each account type within the company.
Now, if all that is desired is to show the totals for each account type within each company, then the only section that we need to show in the report is Group Footer #2. All of the fields (company, account type, sale aggregate) are available in this Footer, so we don't need any of the additional areas.
iam using VFP 9.0...Iam making an invoice report, what i want to know is how to change the contents of the report by changing lets say a combo box in a form. or be able to use select and where clause in the report...any help would be appreciated :)
EDITED FOR CLARIFICATION (per comments instead of direct add into question)
+-----------------+ +-------------------------+
| Contract Form | | Invoice Form |
| | | |
| | | radioCustomer |
| btnInvoiceForm -------> | comboCustomersList |
+-----------------+ | radioContract |
| comboContractsList |
| |
| btnPreviewReport |
+-------------------------+
If I click on the Preview Invoice button, show all records from contract table where customer id (FK) is = to the id picked from the combo box.
If I picked contract from the radio buttons, the contract combo box would work, showing a list of contract id(s), running the report then would show you the record from the contract table where contract id = the id picked from the combo box...
I've edited the message to hopefully better understand your layout of the form(s) with respective radio button combobox controls respectively enabled/disabled. I think you'll need to draw up two distinct reports no matter what showing respective content, then call each one based on the radio button setting... Such as in the "btnPreviewReport" object CLICK event... I've roughed-in on the sample...
if not empty( Thisform.radioControl.radioCustomer.Value )
*/ Customer radio button was selected
xCustomerID = comboCustomersList.Value
*/ Run your Query
select ... from YourTable where ... into cursor C_SampleCustomerData
*/ Run the report
report form YourCustomerReport preview
else
*/ Contract radio button was selected
*/ Customer radio button was selected
xContractID = comboContractsList.Value
*/ Run your Query
select ... from YourTable where ... into cursor C_SampleContractData
*/ Run the report
report form YourContractReport preview
endif
Again, I tried the form as best from your description.
EDIT -- second comment clarification...
The nice thing about reports in VFP is they do not pre-require any hard DBF() in the data environment. However, it would be good to have your data fields set to an Alias.Field reference you are EXPECTING to have. So, if your querying of the data for the Customer report should always have the same expected alias result...
ex:
// pre-close in case the alias we want was already left open previously
use in select( "C_CustomerResults" )
select c1.*;
from YourCustomerTable c1;
where c1.ID = SomeChosenID;
into cursor C_CustomerResults readwrite
Then, in your report, have all your fields to something like
C_CustomerResults.FirstName
C_CustomerResults.LastName
C_CustomerResults.OtherField
This example uses an otherwise long alias name but just for clarification of handling.
I would do a similar for your "contract" results alias. As long as that alias is in use, the report will run against whatever is the current table in use. Nothing fancy, no other prep, no data environment settings needed in the report...
By pre-querying a sample of the data you would have in the report can help you in "roughing" the layout of your report. Then, finish your form to run the query and show the report and you're done.
EDIT -- revised comment follow-up again
Yes... for your customer invoice with multiple lines, same thing... however your report has a header band for things you want to only show once at the top of the page, and a detail band where you would want to show content for your "each line item" of the invoice, and a report footer to show any totals. Depending on complexity, you can add additional "Data Groups" in the report, but start with this now. It sounds like you need to get your feet wet with something working first before you expand on it.
If VFP is your development platform, another website that has dedicated experts in VFP all the time is at www.UniversalThread.com. They also support other forums, but in VFP, they'll get 100+ questions thrown at it a day...