Print Page | Close Window

Formula Error

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=17885
Printed Date: 27 Apr 2024 at 2:28pm


Topic: Formula Error
Posted By: Mike_B1
Subject: Formula Error
Date Posted: 31 Oct 2012 at 4:46am
Hello
I am rather new at Crystal and need to know if my approach to a particular formula is correct.  I have created a report that has parameters: Beginning Period, Beginning Year, End Period, End Year, and Salesman ID.  The report basically shows sales and profit betweem the periods specified.  I want to add annual sales and profit using the invoice date based on the beginning year.  I have so far created a formula for annual cost but recieve a Boolean is required here error in the bold portion of my code.
 
if {?Beginning Period} = [1,2,3] then
{p21_view_invoice_hdr.invoice_date} = DateTime ({?Beginning Year}-1,1,1) to CurrentDate and
(if {p21_view_oe_line.po_cost} > 0 then
{p21_view_oe_line.po_cost} else
if {p21_view_oe_line.commission_cost} > 0 then
{p21_view_oe_line.commission_cost} else
{p21_view_oe_line.sales_cost}) else
{p21_view_invoice_hdr.invoice_date} = DateTime ({?Beginning Year},1,1) to CurrentDate and
(if {p21_view_oe_line.po_cost} > 0 then
{p21_view_oe_line.po_cost} else
if {p21_view_oe_line.commission_cost} > 0 then
{p21_view_oe_line.commission_cost} else
{p21_view_oe_line.sales_cost})
 
Like I said, I am new at this and learning on the fly with no support, so any input will be greatly appreciated.
 
Thank You in advance
 



Replies:
Posted By: comatt1
Date Posted: 31 Oct 2012 at 5:38am
The error is just telling you things in the select have to evaluate to true/false... the syntax is off at the beginning, but in the middle, that stuff won't evaluate to true/false.


if {?Beginning Period} in [1,2,3] then
{p21_view_invoice_hdr.invoice_date} >= DateTime ({?Beginning Year}-1,1,1) and {p21_view_invoice_hdr.invoice_date} <=CurrentDate
else
{p21_view_invoice_hdr.invoice_date} >= DateTime ({?Beginning Year},1,1) and {p21_view_invoice_hdr.invoice_date} <=CurrentDate

----

This above is all I would add to the select, the rest I would add to formulas.


I don't think you should have this in the select, add to a formula within the report

(if {p21_view_oe_line.po_cost} > 0 then
{p21_view_oe_line.po_cost} else
if {p21_view_oe_line.commission_cost} > 0 then
{p21_view_oe_line.commission_cost} else
{p21_view_oe_line.sales_cost})



-----------------
----------------
f {?Beginning Period} = [1,2,3] then
{p21_view_invoice_hdr.invoice_date} = DateTime ({?Beginning Year}-1,1,1) to CurrentDate and
(if {p21_view_oe_line.po_cost} > 0 then
{p21_view_oe_line.po_cost} else
if {p21_view_oe_line.commission_cost} > 0 then
{p21_view_oe_line.commission_cost} else
{p21_view_oe_line.sales_cost}) else
{p21_view_invoice_hdr.invoice_date} = DateTime ({?Beginning Year},1,1) to CurrentDate and
(if {p21_view_oe_line.po_cost} > 0 then
{p21_view_oe_line.po_cost} else
if {p21_view_oe_line.commission_cost} > 0 then
{p21_view_oe_line.commission_cost} else
{p21_view_oe_line.sales_cost})


Posted By: Mike_B1
Date Posted: 31 Oct 2012 at 7:45am
Thank you for your response.  I guess my next question would be if I were to put the code you specified into the select, would it contradict the date range I have already put in?  The end user specifies the start and end period and year for a given range.  Here is my select.
 
{p21_view_ship_to_salesrep.primary_salesrep} = "Y" and
not ({p21_view_oe_line.detail_type} in [1, 2]) and
{p21_view_oe_line.assembly} <> "" and
{p21_view_invoice_hdr.bill2_name} startswith "" and
not ({p21_view_invoice_line.product_group_id} in ["FILEQU", "FILSUP"]) and
{p21_view_oe_line.cancel_flag} = "N" and
{p21_view_oe_line.complete} = "Y" and
{p21_view_oe_line.delete_flag} = "N" and
{p21_view_invoice_hdr.salesrep_id} = {?Salesman ID} and
(if {?Beginning Year}= {?End Year}
then
{p21_view_invoice_hdr.year_for_period}= {?Beginning Year} and {p21_view_invoice_hdr.period} in {?Beginning Period} to {?End Period}
else
({p21_view_invoice_hdr.year_for_period} in {?Beginning Year} to ({?End Year}-1) and {p21_view_invoice_hdr.period} in {?Beginning Period} to 12) or
({p21_view_invoice_hdr.year_for_period} = {?End Year} and {p21_view_invoice_hdr.period} in 1 to {?End Period}))
 

Thank you



Print Page | Close Window