Crystal Report - Conditional selection of record - crystal-reports

I'm using Crystal Reports XI.
My data is coming from a dataset.
I have 2 tables which are related as follows:
Product(ProdID(PK), ProdName)
ProdPC(ProdPCID(PK), ProdID(FK), PCType, ProdCode)
The 'PCType' field determins the type of barcode format the 'ProdCode' represents. (E.g. EAN13, EAN8).
In crystal reports one 'Product' can have more than one kind of barcode which means my tables end up looking like this:
Product: ("1", "Example Product 1")
ProdPC: ("0", "1", "EAN8", "01234567"), ("1", "1", "EAN13", "012345678910")
In crystal reports I only want to print 1 barcode label for per product. However because they're are 2 records in the 'ProdPC' table, I will get 2 labels being printed for this 1 product.
What I want to do is place a condition in crystal reports which states, "If EAN13 is NULL then display EAN8, ELSE display EAN13"
I do not have access to the dataset and cannot prevent the application which calls Crystal Reports to create the barcode labels from sending more than 1 record for the 'ProdPC' table.
How can I create my conditional statement, purely in 'Crystal Reports 2008'?
What I have tried so far is:
IF {PartPC.PCType} = "EAN-13" AND {PartPC.ProdCode} <> "" THEN
{PartPC.ProdCode}
ELSE
/* DISPLAY PartPC.ProdCode containing EAN8 value */
;
But I am unsure how to then tell Crystal Reports to display the 'ProdCode' value where 'PCType' is equal to 'EAN8'

Group your report by Product ID.
Order your report by PC Type descending (within Product ID).
Include your report details in the Product ID footer (not the details section).

Option I: create two columns: one for each bar code. Do this in Crystal Reports.
Remove the PartPC table, replacing it with two SQL Expression fields:
// {%EAN-8}
(
SELECT ProdCode
FROM PartPC
WHERE ProdID=Product.ProdID
AND PCType='EAN-8'
)
// {%EAN-13}
(
SELECT ProdCode
FROM PartPC
WHERE ProdID=Product.ProdID
AND PCType='EAN-13'
)
Then create a formula field to display the appropriate one:
// {#barcode}
If Not(Isnull({%EAN-13})) Then
{%EAN-13}
Else
{%EAN-8}
Option II: alter the SQL to create to scalar-valued fields. Do this in your dataset or in a Command object (Crystal Reports).
SELECT Product.*,
(
SELECT ProdCode
FROM PartPC
WHERE ProdID=Product.ProdID
AND PCType='EAN-8'
) EAN_8,
(
SELECT ProdCode
FROM PartPC
WHERE ProdID=Product.ProdID
AND PCType='EAN-13'
) EAN_13
FROM Product
...

Related

Filter portal for most recently created record by group

I have a portal on my "Clients" table. The related table contains the results of surveys that are updated over time. For each combination of client and category (a field in the related table), I only want the portal to display the most recently collected row.
Here is a link to a trivial example that illustrates the issue I'm trying to address. I have two tables in this example (Related on ClientID):
Clients
Table 1 Get Summary Method
The Table 1 Get Summary Method table looks like this:
Where:
MaxDate is a summary field = Maximum of Date
MaxDateGroup is a calculated field = GetSummary ( MaxDate ;
ClientIDCategory )
ShowInPortal = If ( Date = MaxDateGroup ; 1 ; 0 )
The table is sorted on ClientIDCategory
Issue 1 that I'm stumped on: .
ShowInPortal should equal 1 in row 3 (PKTable01 = 5), row 4 (PKTable01 = 6), and row 6 (PKTable01 = 4) in the table above. I'm not sure why FM is interpreting 1Red and 1Blue as the same category, or perhaps I'm just misunderstanding what the GetSummary function does.
The Clients table looks like this:
Where:
The portal records are sorted on ClientIDCategory
Issue 2 that I'm stumped on:
I only want rows with a ShowInPortal value equal to 1 should appear in the portal. I tried creating a portal filter with the following formula: Table 1 Get Summary Method::ShowInPortal = 1. However, using that filter removes all row from the portal.
Any help is greatly appreciated.
One solution is to use ExecuteSQL to grab the Max Date. This removes the need for Summary functions and sorts, and works as expected. Propose to return it as number to avoid any issues with date formats.
GetAsTimestamp (
ExecuteSQL (
"SELECT DISTINCT COALESCE(MaxDate,'')
FROM Survey
WHERE ClientIDCategory = ? "
; "" ; "";ClientIDCategory )
)
Also, you need to change the ShowInPortal field to an unstored calc field with:
If ( GetAsNumber(Date) = MaxDateGroupSQL ; 1 ; 0 )
Then filter the portal on this field.
I can send you the sample file if you want.

MDX: Top 10 with filtered members

I'm creating a report for JasperServer in iReport. I am creating a report with the top 10 companies with most product downloads of the selected products. Users can select in JasperReports which products with a list (parameter {$P{ProductFormat}}).
My dimension for products has the following structure: [Product].[ProductFactory].[ProductType], so input for the parameter for example can be: [Product].[ProductCategory1].[Product1], [Product].[ProductCategory2].[Product2], ... I also want those products available as rows so I can use them as fields in iReport. (product in where is not an option)
SELECT
NON EMPTY {
[Measures].[Orders]
} ON COLUMNS,
NON EMPTY
Crossjoin({TopCount({[USER_COMPANY].[Company].Members}, 10, [Measures].[Orders])}, {$P{ProductFormat}})
ON ROWS
FROM [Products]
WHERE $P{DateFilter}
This query return the top 10 companies of all products with the data filtered per products. I want a top 10 companies of the selected products, but I can't get it to work with topcount and as a row.
This query against AdvWrks via SSMS seems to work ok:
WITH
SET [ProductFormat] AS
{
[Product].[Product Categories].[Category].[Bikes]
,[Product].[Product Categories].[Category].[Clothing]
,[Product].[Product Categories].[Category].[Components]
}
SELECT
[Measures].[Reseller Sales Amount] ON 0
,Generate
(
[ProductFormat]
,
[Product].[Product Categories].CurrentMember
*
TopCount
(
[Geography].[Geography].[City].MEMBERS
,5
,[Measures].[Reseller Sales Amount]
)
) ON 1
FROM [Adventure Works];
It returns the following:
If I add a WHERE clause like the following then it seems to be context aware:
WHERE [Date].[Calendar].[Calendar Year].&[2006];

This field cannot be summarized crystal report error

I've got the problem about crystal report. I've created one formula field called PAT_DEP and formula is as follow.
Local NUMBERVAR PAT_DEP_AMT := 0;
IF NextIsNull({MYOBJ.PAT_DEPOSIT}) = TRUE THEN
(
IF {MYOBJ.PAT_DEPOSIT} = PREVIOUS({MYOBJ.PAT_DEPOSIT}) THEN
(
PAT_DEP_AMT := 0;
)
ELSE
(
PAT_DEP_AMT := {MYOBJ.PAT_DEPOSIT};
);
)
ELSE
(
IF PREVIOUS({MYOBJ.PAT_DEPOSIT}) = NEXT({MYOBJ.PAT_DEPOSIT}) THEN
(
PAT_DEP_AMT := ToNumber(0);
)
ELSE
(
PAT_DEP_AMT := {MYOBJ.PAT_DEPOSIT};
);
)
Then I've created another formula field called TOT_PAT_DEP and formula is as follow like summarized above formula field.
TOTAL_PAT_DEP := SUM(#PAT_DEP)
But got crystal report error This field cannot be summarized crystal report error. Please help me how come I got this error.
Based on your explanation and formula, it looks like you have a one-to-many relationship which is causing you some difficulty. Let's take an example:
Order Table
Order #, Total, Paid
Order Items Table
Order #, Line #, Description
When you join the two tables you can no longer sum the total/paid columns because they will be multiplied by the number of order lines.
The way to overcome this is to create a group using the key. In my example you would group on Order #. You can then create a running total to sum the total/paid columns but will only evaluate on the change of your Order # group.
Does that make sense?

Null when using Jasper report list component?

When select field and adding it to list component in jasper report it can't display values from database it return null
Query for it data set
SELECT TRAFFIC."DESC", INC.UNBILLED_AMOUNT FROM INC_CONTRACT_USAGE INC
INNER JOIN TRAFFIC_SERVICE TRAFFIC ON TRAFFIC.TRAFFIC_SERVICE_ID = INC.TRAFFIC_SERVICE_ID
WHERE INC.TRAFFIC_SERVICE_ID IN (1,2,3)

Crystal Report with multiple datasources, one is empty

I have a Crystal report with a table as a datasource and I want to include another table with details for the report footer.
I have two data sources in the report which are not linked, but when the selection criteria returns no rows from the main table, the results from the non-empty non-linked source are also empty.
I suspect it's doing a cross join between the two datasources, so if one is empty, that joined with another is also empty. The problem is I need my rows from the non-empty table to show in the report footer section, and they're getting suppressed by the other, empty datasource.
How can I get rows from an independent table to show in the report footer when the selection criteria and their parameter choices return an empty result set in the main table?
Thanks for your help,
-Beth
Also, I tried using a command as a datasource with sql like this:
select * from waitlist
union all
select distinct null as reportID, null as ..., lastupdated
from waitlist
but it still returns null for lastupdated and suppresses the subreport in the report footer.
I ended up setting my report datasource to a view which unioned another row to the table. I also needed to change my selection criteria so it allows this row to pass through.
Here's my datasource:
CREATE VIEW [dbo].[vw_rpt_waitlist] AS
select * from waitlist
union all
select distinct
reportID,
null as (fields...),
lastupdated,
'reserved' as countyName
from
waitlist
and here's my record selection formula:
({vw_rpt_waitlist.countyName} = {?County} or
{vw_rpt_waitlist.countyName} = "reserved") and
{vw_rpt_waitlist.reportID} = 14
I'm also suppressing the detail section if there were real rows returned:
formula = {vw_rpt_waitlist.countyName} = "reserved"
and to get the parameterized county name they selected in the page header of the report, I'm using:
dim t as string
dim c as string
if {vw_rpt_waitlist.countyName}="reserved" then
c = {?County}(1)
else
c = {vw_rpt_waitlist.countyName}
end if
t = "Waitlist by " + {#serviceTitle} + " and Waiver Need Index as of "
+ cstr({vw_rpt_waitlist.lastUpdated},"MM/dd/yyyy")
formula = t
Since the 'reserved' county always comes through, the subreports are not suppressed.