creating a crystal parameter from a formula output - crystal-reports

In my report there is a Purchasing Group number with values like 100,101,102....201,202,203..301,302,303... etc.
There is a formula to identify the Purchasing group department -
If {PURGRP} startswith '1'
then 'Purchasing Dept.'
else
if {PURGRP} startswith '2'
then 'Construction Agreements Office'
else
if {PURGRP} startswith '3'
then 'Storerooms'
else......
The report is grouped by these departments. i am trying to create a parameter which allows the user to select the Department by the names in the formula, but i am not able to append these names to available values as they are derived from a formula. One option is hard coding the values, but I was hoping there could be a more dynamic way.

My first thought was to capture all the department names in shared array, but I don't see any way to attach that to the parameter.
In all likelihood, having a separate lookup table in your main database is the simplest and least error-prone path. I suppose you could write a maketable query that would make your lookup table dynamic, but Crystal Reports isn't built for this purpose.

Related

In SSRS, can you group multiple parameter values into one?

I am relatively new to SSRS but have been working with SQL for years. I have been tasked with creating a report that reflects shipped items based on their status. For example, I have x number of items with varying statuses including "IN_TRANSIT", "RECEIVING", "SHIPPED", "WORKING", and "CLOSED". The requestor is asking if I can provide the following options in a report drop down:
"IN_PROCESS" Status filter including all statuses except "CLOSED".
"CLOSED".
Essentially, they want to be able to view all non closed statuses, closed, statuses, or all. Right now, I have it set so you can individually select all statuses, essentially getting them the data they want, just not with the "right" parameters.
My question is, does SSRS provide a way to essentially 'group' the non-closed statuses into one inside the report so that when they select "IN_PROCESS" it sends those non-closed statuses to the SQL query I have built in? The problem with using SQL for this is that the dataset I created to generate the dropdown options provides "CLOSED" and "IN_PROCESS" as it's output options, but when they select "IN_PROCESS" (sending that value to the filter in the report), since it's not an actual status, nothing comes back.
If more information or clarification is required, please let me know.
Thanks ahead of time!
You can create a new column in your SQL query and use a CASE statement to give the value of IN_PROCESS or CLOSED for the applicable status. Then you will just need to the filtering condition to match the SSRS parameter to the new column.
Depending on how often this case is likely to be reused should help determine how to approach it. If it sounds like it might become a regular process.... "Oh can we have another report with the same filter but showing xyz " then take the time to setup correctly and it will save time in the future.
Personally I would add a database table, if possible, that contains the status names and then a status group name (ignoring fully normalising for the sake of simplicity here).
CREATE TABLE StatusGroups(Status varchar(10), StatusGroup varchar(10))
INSERT INTO StatusGroups VALUES
('IN_TRANSIT', 'In Process'),('RECEIVING, 'In Process'),('SHIPPED', 'In Process'),('WORKING', 'In Process'),('CLOSED' 'Closed')
Then a simple view
CREATE MyNewView AS
SELECT t.*, g.StatusGroup
FROM MyTable t
JOIN StatusGroups g on t.STATUS = g.Status
Now change your report dataset query to use this view passing in the report parameter like this...
SELECT *
FROM MyNewView
WHERE StatusGroup = #myReportParameter
Your dataset for your report parameter's available values list could then be something like
SELECT DISTINCT StatusGroup FROM StatusGroups
This way if you every add more status or statusgroup values you can add an entry to this table and everything will work without ever having to edit your report.

Consolidate rows in report

If a row has the same ID as the last one, I want to combine them - summing up the cubicFt and Savings. $perFt divides the savings by the cubicFt, so it wouldn't be summed, simply dividing the new results. I also want the Descriptions to be concatenated, like this:
Make a Group based on ID (or whatever the leftmost column is). Then suppress the Details section and the Group Header. Instead, you'll be putting all the fields you want to display in the Group Footer. From there it's simple:
Create a Summary or Running Total for both cubicFt and Savings.
Reconfigure your $PerFt to use the summary/running total fields you made in step 1.
Combine the Descriptions by creating a shared string variable Descriptions. Whenever the group changes, reset it with Descriptions = "". Whenever the group doesn't change, add the description string to your variable. Something like:
Descriptions = Descriptions & " ; " & {yourtable.Description}
Then create a final formula ShowDescription in the Group Footer to display the results with RIGHT(Descriptions, LEN(Descriptions)-2)
You need to do grouping, either by modifying the SELECT statement or the stored query that generates the data, or within Crystal Reports. I'm literally 20 years out of date on Crystal Reports, although I have used similar software, so this will have to be tweaked.
For the first solution, all you need is a concatenation aggregation function for the string field. Your DB may or may not have one built in, so you may need to add it.
SELECT Building, ID,
SUM(cubicFt), SUM(savings),
SUM(savings)/SUM(cubicFt) AS [$perft],
LEFT(STRING_AGG(description, ';'), -1) -- drop extra ; at end
GROUP BY Building, ID;
However, you should be able to do the same within Crystal by setting this up as a subtotal group (not sure if you have to do user definitions for the string aggregation), and then hiding the detail section.

Display one Column as Multiple Columns

I have Table Structure Like
I am Using Visual Studio 2013 and Crystal Report 13.0.12
You could use a Cross Tab for this, but you'll get more freedom by not using one:
In your report, group by Customer Name, then by TestName. Suppress all 5 of these sections except for the Group Footer of Customer Name. Here, place Customer Name, Result, and a new formula named Sugar. And inside sugar put this code:
PREVIOUS({Result})
Assuming there's no other TestNames besides Protein and Sugar, and assuming every Customer has one value for each, you should get the desired results in the footer. Let me know if that's the case and I can update the answer to accommodate.

Crystal Reports 7 CrossTab Suppress Column

I'm trying to modify a report created in Crystal Reports 7 (which I know almost nothing about). I want to use a CrossTab, as this seems to be the best way to accomplish what I want. I have a column with three possible values: A, B, C. The cross tab creates three columns. I want to suppress C. How can I do this?
Also, is there anyway to create rows based on one field (i.e. a PK value), but display another - like a description? For example, if a list of states have a PK value of 1-50, I want them ordered by PK, but I want to display the state name.
All you ask is possible;
i suggest not to use cross tab: cross tab is intended for an uknown number of rows and columns (varying on data) ad for summarizing (max value, sum of values) results on a grid.
you should, instead:
Create a blank report
Drop the fields from the Field explrorer into the Details Section (just A and B columns)
Use Report Sort Expert to sort elements no the PK value

Crystal Reports sort by subreport

So I have a series of orders that come in everyday. We add them to a database and then use Crystal Reports make packing sheets of these orders. We have two tables one for order information(name, address, order number, etc) and one for the items. In Crystal Report we use the order for the report and then do a subreport with all the item associated with order number. Now I have been given the requirement that we need to all the orders sorted by the first item's item number. How do I sort a report by a field in a subreport?
First of all, you can accomplish this report w/o a subreport. The report would be grouped by order # w/ the order fields in the group header. The Details section would contain the order-items.
In any case (my approach or yours), if you just need to sort the order-items by item number, simply reference that field in the Record Sort Expert.
If you need to sort the orders by each order's order-items[0] (the first item in the list), you'll need to create a SQL Expression that returns the item #. If you add a group on the SQL Expression field, then make that the top-level group (G1), the report will group first by the SQL Expression, then by the Order #. The SQL Expression should resemble:
(
//this will select the numerically-smallest item# for a given order#
SELECT min(item #)
FROM order-items
//correlate to 'main' query
WHERE order#=order.order#
)
If you need more complex rules for 'first item #' (whatever that means), you need to include it in the SQL Expression.