Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crystal formula with multiple conditions in each if statement

Status
Not open for further replies.

CMDorsey

Technical User
Oct 26, 2005
4
US
I need help with the following formula...I have multiple conditions in each if statement but not sure how to write the formula -

if {SO_SalesOrderHeader.UDF_CONSOLIDATED_SHIPMENT} = "N" and {SO_SalesOrderHeader.UDF_ON_TIME_SHIPMENT} = "Y" and {SO_SalesOrderHeader.UDF_SHIP_ASAP} = "N"
then "** ON-TIME SHIPMENT **"
else if {SO_SalesOrderHeader.UDF_CONSOLIDATED_SHIPMENT} = "N" and {SO_SalesOrderHeader.UDF_ON_TIME_SHIPMENT} = "N" or {SO_SalesOrderHeader.UDF_SHIP_ASAP} = "Y"
then "** SHIP ASAP **"
else if {SO_SalesOrderHeader.UDF_CONSOLIDATED_SHIPMENT} = "Y" and {SO_SalesOrderHeader.UDF_ON_TIME_SHIPMENT} = "Y" or {SO_SalesOrderHeader.UDF_SHIP_ASAP} = "N"
then "** ON-TIME SHIPMENT / CONSOLIDATE **"
else if {SO_SalesOrderHeader.UDF_CONSOLIDATED_SHIPMENT} = "Y" and {SO_SalesOrderHeader.UDF_ON_TIME_SHIPMENT} = "N" or {SO_SalesOrderHeader.UDF_SHIP_ASAP} = "Y"
then "** SHIP ASAP / CONSOLIDATE **"
else if {SO_SalesOrderHeader.UDF_CONSOLIDATED_SHIPMENT} = "Y" and {SO_SalesOrderHeader.UDF_ON_TIME_SHIPMENT} = "N" or {SO_SalesOrderHeader.UDF_SHIP_ASAP} = "N"
then "** CONSOLIDATE **"
else "** FIX FORMULA **
 
Whenever you mix and AND with an OR you are likely to run into problems unless you force the order of operation using brackets.

Without understanding the conditions you are testing, this could be incorrect but should give you an idea of what I mean:

Code:
if 	{SO_SalesOrderHeader.UDF_CONSOLIDATED_SHIPMENT} = "N" and 	
	{SO_SalesOrderHeader.UDF_ON_TIME_SHIPMENT} = "Y" and 	
	{SO_SalesOrderHeader.UDF_SHIP_ASAP} = "N"
then 	"** ON-TIME SHIPMENT **" 
else 
if 	{SO_SalesOrderHeader.UDF_CONSOLIDATED_SHIPMENT} = "N" and 	
	(
		{SO_SalesOrderHeader.UDF_ON_TIME_SHIPMENT} = "N" or 			
		{SO_SalesOrderHeader.UDF_SHIP_ASAP} = "Y"
	)
then 	"** SHIP ASAP **"
else 
if 	{SO_SalesOrderHeader.UDF_CONSOLIDATED_SHIPMENT} = "Y" and
	(
		{SO_SalesOrderHeader.UDF_ON_TIME_SHIPMENT} = "Y" or 	
		{SO_SalesOrderHeader.UDF_SHIP_ASAP} = "N"
	)
then 	"** ON-TIME SHIPMENT / CONSOLIDATE **"
else 
if 	{SO_SalesOrderHeader.UDF_CONSOLIDATED_SHIPMENT} = "Y" and 		
	(
		{SO_SalesOrderHeader.UDF_ON_TIME_SHIPMENT} = "N" or 		
		{SO_SalesOrderHeader.UDF_SHIP_ASAP} = "Y"
	)
then 	"** SHIP ASAP / CONSOLIDATE **"
else 
if 	{SO_SalesOrderHeader.UDF_CONSOLIDATED_SHIPMENT} = "Y" and 		
	(
		{SO_SalesOrderHeader.UDF_ON_TIME_SHIPMENT} = "N" or 			
		{SO_SalesOrderHeader.UDF_SHIP_ASAP} = "N"
	)
then 	"** CONSOLIDATE **" 
else 	"** FIX FORMULA **"

You could probably simplify the code somewhat using nested IF statements, something like this:

Code:
if 	{SO_SalesOrderHeader.UDF_CONSOLIDATED_SHIPMENT} = "N"
then	if	{SO_SalesOrderHeader.UDF_ON_TIME_SHIPMENT} = "Y" and 	
		{SO_SalesOrderHeader.UDF_SHIP_ASAP} = "N"
	then 	"** ON-TIME SHIPMENT **" 
	else
	if	{SO_SalesOrderHeader.UDF_ON_TIME_SHIPMENT} = "N" or 			
		{SO_SalesOrderHeader.UDF_SHIP_ASAP} = "Y"
	then 	"** SHIP ASAP **"
	else	"** FIX FORMULA **" 
else	
if 	{SO_SalesOrderHeader.UDF_CONSOLIDATED_SHIPMENT} = "Y"
then 	if	{SO_SalesOrderHeader.UDF_ON_TIME_SHIPMENT} = "Y" or 	
		{SO_SalesOrderHeader.UDF_SHIP_ASAP} = "N"
	then 	"** ON-TIME SHIPMENT / CONSOLIDATE **"
	else
	if 	{SO_SalesOrderHeader.UDF_ON_TIME_SHIPMENT} = "N" or 		
		{SO_SalesOrderHeader.UDF_SHIP_ASAP} = "Y"
	then	"** SHIP ASAP / CONSOLIDATE **"
	else
	if	{SO_SalesOrderHeader.UDF_ON_TIME_SHIPMENT} = "N" or 			
		{SO_SalesOrderHeader.UDF_SHIP_ASAP} = "N"
	then	"** CONSOLIDATE **"
	else	"** FIX FORMULA **"
else	"** FIX FORMULA **"

Note that the formatting is not important. I just find it much easier to understand the formula and visualise the logic if it is set out this way.

Hope this helps

Cheers
Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top