Display all orders in which a certain product was purchased - Crystal Reports - crystal-reports

I've searched all over many sites today and I am unable to find an answer to this. I am trying to display all orders in which a certain product (scarf) was purchased. For Example:
Order #1
Hat $3.00
Scarf $5.00
Order #2
Puzzel $2.00
Order #3
Scarf $5.00
With this example, I'd like to display records #1 and #3, in which a scarf was purchased, but also include "Hat" that was purchased along with the scarf in Order #1...(while excluding Order #2)
Output should be:
Order #1
Hat $3.00
Scarf $5.00
Order #3
Scarf $5.00
I've tried using instr functions to filter this information out, as well as looks for various formulas, but I cannot seem to figure this out. I appreciate everyone's time!
John

Create a SOL-expression field:
// {%order_has_scarf}
// assumes table in main report is `orders`
(
SELECT count(1) total
FROM orders o
WHERE o.order_id = orders.order_id
)
Alter record-selection formula:
AND {%order_has_scarf} > 0

Create a group of orders first then place the fields in detail (Hat..etc) and write a supress condition for detail and group like:
if Order="PUZZEL"
then true
else false
with this condition if puzzel is encountered then both detail and group are supressed.

Thanks everyone, i actaully figured out how to do this. I added another instance of the Order Details table to my crystal report, then I filtered that table by the Item ID related to the scarf, then linked that to the original order table...that way, only orders containing this particular Item ID would be passed to the original table.
Hope this makes sense!

Related

Filtering groups in crystal reports

Ok, simple question to anyone who has experience with crystal (which I do not) ,
but I have a report that is pulling in open orders, items ordered, qty ordered, and qty on hand. I am grouping by order # and would like to filter out all the orders that have any items with insufficient qty on hand for any item on the order to ship. I tried a simple formula of {qty_on_ord} < {qty_on_hand} then {Ord_no}, and inserted this into the group header, but it didn't work. My end result basically wanted is: if an item has insufficient qty, then don't display the order at all, and could also go vice-versa and show the orders that are short, with a simple change of <>. Im sure this is simple, but I have no experience in crystal reports and have spent more time than I wanted searching the web.
Any help is greatly appreciated.
Insert your formula at the Detail(Record) Level.
Go To Report > Selection Formulas > Record
There Enter your formula by selecting Fields from the "Report Fields"
This way you can just select the order Numbers you want and wont have to worry about the sum or totals at the bottom.

Group items based on a formula

I am creating an invoice using Crystal Reports & I want to group products which have the same PRO_ID into one line, for this I have created a GROUP and it works fine.
Following is a sample of the data
PRO_ID NAME ORDER_QTY
0001 Battery 2
0001 Battery -6
0001 Battery 3
In the second line the quantity is a minus because of a returned item. I want to show the actually ordered items separately & returned items separately.
At the moment the report shows -1 for the ORDER_QTY because it just groups the Products based on the PRO_ID. How can I group these separately ?
try this:
Keep PRO_ID as it is as the first group and then create a sub group #group2 and write below code:
if ORDER_QTY<0
then "Returned"
else "Actual"
Use #group2 to group after PRO_ID.
Now place the all your fields in details.
hope this helps

Comparing Records In Crystal Reports

So I want to compare some records in Crystal Reports to take care of a problem a bug in our system has caused.
So every once in a while our system charges someone twice. I want to find all those orders/shipments. An order can have multiple shipments (if we have one item on backorder we ship out the rest of the order in one shipment and then ship out the backordered item in another shipment). The shipment also has a charge_date field that's a date time stamp when we charged the customer. So if we grouped it in Crystal reports it would look like this:
Order Id: 234587
Shipment Id: 121 charge_date: 8/29/2012 11:43:21
Shipment Id: 524 charge_date: 9/1/2012 15:37:39
Shipments are created in numerical order. So if we send out one shipment, say shipment number: 345, then the next shipment we send out, regardless of what order it's a part of, will be shipment number: 346.
So, when someone is a victim of our bug then their shipments are right after one another and their charge_date are exactly the same. Like so:
Order Id: 69875
Shipment Id: 594 charge_date: 9/2/2012 14:32:15
Shipment Id: 595 charge_date: 9/2/2012 14:32:15
I can create a list of just shipments and their charge date (without grouping on Order Id) and sorting them in ascending order. But what I want to do is iterate through the list of shipments and compare each shipment to the previous shipment and see if the charge_date's are equal and if they are then select them or mark them or something so that I can group them by a formula and take care of them.
Is this possible in Crystal? Should I use a different program? I realize this might not be the best way to do this so I'm open to suggestions. Thanks in advance!
Can you create groups for the orderID and chargeDate, then suppress all shipment details unless the count(shipmentID) > 1?
You'd display the shipment details in the chargeDate group footer.
Use the Previous function:
// {#Is Error}
If Previous({table.chargeDate})={table.chargeDate}) Then
true
Else
false
Insert a group in this formula.
I'm not able to test this, as I'm not at my work computer.

Faster CROSS JOIN alternative - PostgreSQL

I am trying to CROSS JOIN two tables, customers and items, so I can then create a sales by customer by item report. I have 2000 customer and 2000 items.
SELECT customer_name FROM customers; --Takes 100ms
SELECT item_number FROM items; --Takes 50ms
SELECT customer_name, item_number FROM customers CROSS JOIN items; Takes 200000ms
I know this is 4 million rows, but is it possible to get this to run any faster? I want to eventually join this with a sales table like this:
SELECT customer_name, item_number, sales_total FROM customers CROSS JOIN items LEFT JOIN sales ON (customer.customer_name = sales.customer_name, item.item_number=sales.item_number);
The sales table will obviously not have all customers or all items, so the goal here is to have a report that shows all customers and all items along with what was sold and not sold.
I'm using PostgreSQL 8.4
To answer your question: No, you can't do a cross join faster than that - if you could then that would be how CROSS JOIN would be implemented.
But really you don't want a cross join. You probably want two separate queries, one which lists all customers, and another which lists all items and whether or not they were sold.
This really needs to be multiple reports. I can think of several off the top of my head that will yield more efficient packaging of information:
Report: count of all purchases by customer/item (obvious).
Report: list of all items not purchased, by customer.
Report: Summary of Report #2 (count of items) in order to prioritize which customers to focus on.
Report: list of all customer that have not bought an item by item.
Report: Summary of Report #3 (count of customers) in order to identify both the most popular and unpopular items for further action.
Report: List of all customers who purchased an item in the past, but did not purchase it his reporting period. This report is only relevant when the sales table has a date and the customers are expected to be regular buyers (i.e. disposable widgets). Won't work as well for things like service contracts.
The point here is that one should not insist that the tool process every possible outcome at once and generate more data and anyone could possibly digest manually. One should engage the end-users and consumers of the data as to what their needs are and tailor the output to meet those needs. It will make both sides' lives much easier in the long run.
If you wish to see all items for a given client (even if the cient has no items), i would rather try
SELECT c.customer_name, i.item_number, s.sales_total
FROM customers c LEFT JOIN
sales s ON c.customer_name = s.customer_name LEFT OIN
items i on i.item_number=s.item_number
This should give you a list of all clients, and all items joined by sales.
Perhaps you want something like this?
select c.customer_name, i.item_number, count( s.customer_name ) as total_sales
from customers c full join sales s on s.customer_name = c.customer_name
full join items i on i.item_number = s.item_number
group by c.customer_name, i.item_number

Show Report group even when no records selected

I'm trying to show employees at a company grouped by worked and still working (in vs2005 crystal reports).
The user can pass by parameter a list of companies they want to show.
Tables: VRP-COMPANY, VRP-COMPANY-OPPORTUNITY, VRP-OPPORTUNITY-PRODUCT
The record selection formula: {VRP-COMPANY.COMPANY company} in {?companies}
Grouping is done on: VRP-COMPANY.COMPANY company, then formula to decide its working or worked and then on productname.
Now when I run the report I only get to see the companies who have got entries in the VRP-COMPANY-OPPORTUNITY. I want to see the company name (group) even if there are no entries in the opportunity table. How to do this in Crystal Reports? I tried Left join between company and company-opportunity tabel but no effect.
I found the problem. Left join was correct but I had an additional select formula (on opportunity status to be closed-won. Therefore it let out the record. The record can also be null when there are no opportunities.
Should the question be deleted?