Print Page | Close Window

Nested Formula

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=22058
Printed Date: 01 May 2024 at 4:42pm


Topic: Nested Formula
Posted By: Wood
Subject: Nested Formula
Date Posted: 16 Aug 2016 at 7:32am
I am trying to run the following nested formula and the second and third if/thens work but the first one "Board" returns 0. I do not see the error. The selection section will find "Board" and return a good report but the formula={@Extension}*0.03 in this formula returns 0


if{V_ORDER_HIST_LINE.USER_1}="Board"then
formula={@Extension}*0.03
elseif{V_ORDER_HIST_LINE.USER_1}="Boy"then
formula={@Extension}*0.01
elseif{V_ORDER_HIST_HEAD.USER_1}="Dog"Then
formula={@Extension}*0.01
elseif{V_ORDER_HIST_HEAD.USER_1}="Tail"Then
formula={@Extension}*0.006
elseif{V_ORDER_HIST_HEAD.USER_1}="Hair"Then
formula={@Extension}*0.05
elseif{V_ORDER_HIST_HEAD.USER_1}="Car"Then
formula={@Extension}*0.02
elseif{V_ORDER_HIST_HEAD.USER_1}="Step"Then
formula={@Extension}*0.01
elseif{V_ORDER_HIST_HEAD.USER_1}="World"Then
formula={@Extension}*0.01
End if



Replies:
Posted By: kevlray
Date Posted: 16 Aug 2016 at 7:55am
Personally I prefer to use the switch function instead of nested if's , example:

switch({V_ORDER_HIST_LINE.USER_1}="Board", formula={@Extension}*0.03, {V_ORDER_HIST_LINE.USER_1}="Boy", formula={@Extension}*0.01, etc.)


Posted By: Wood
Date Posted: 16 Aug 2016 at 8:28am
Thank you for the response. I received an error,

"A number, currency amount, boolean, date, time, date-time, or string is required here."

and it hi-lights the first instance of formula.

switch({V_ORDER_HIST_LINE.USER_1}="Board",formula={@Extension}*0.03)

Sorry I am not a programmer.


Posted By: kevlray
Date Posted: 16 Aug 2016 at 12:26pm
Opps did not notice that you were using BASIC format.  It should look like this.

formula = switch({V_ORDER_HIST_LINE.USER_1}="Board", {@Extension}*0.03, {V_ORDER_HIST_LINE.USER_1}="Boy", {@Extension}*0.01, etc.)




Posted By: Wood
Date Posted: 17 Aug 2016 at 4:00am
Thank you for your reply! This works great.



Print Page | Close Window