Focal Point
[SOLVED] if-then-else

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/7551040992

September 11, 2008, 03:36 PM
Donald
[SOLVED] if-then-else
I need to construct some logic to check a 12 month period and display the first value that is greater than zero. In my if-then logic I need it to stop after the first value is found.

This message has been edited. Last edited by: Kerry,


Prod: WebFocus 7.7.3 Win 2003
Dev: WebFocus 7.7.3 Win 2003
September 11, 2008, 04:28 PM
Prarie
Donald...I think we need a little more detail here...or maybe it's just been a long day.


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
Yes its been a long day. But what I need to do is check 12 monthly buckets (Jan - December) If the value in January is greater than zero display that value. But if January is zero I need to check each bucket until I have a value. If there is no value in any of the 12 months then display a zero. For example:If there is a value in February I need to stop so I don't add March. I need to display February and stop processing.


Prod: WebFocus 7.7.3 Win 2003
Dev: WebFocus 7.7.3 Win 2003
These buckets, are they columns or are they rows?

Columns:

Jan  Feb  Mar  Apr  etc.
---- ---- ---- ----
0000 0001 0002 0001 etc.

Rows:

Month Amount
----- ------
01      0000
02      0001
03      0002
04      0001
etc.


If they're rows and you have the month as a column, this may work:

SUM
AMOUNT
BY LOWEST 1 MONTH
WHERE AMOUNT GT 0



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
If they're columns, then this might work:

NEWAMT/D6 = 
IF JANAMT GT 0 THEN JANAMT ELSE
IF FEBAMT GT 0 THEN FEBAMT ELSE
IF MARAMT GT 0 THEN MARAMT ELSE
IF APRAMT GT 0 THEN APRAMT ELSE
IF MAYAMT GT 0 THEN MAYAMT ELSE
IF JUNAMT GT 0 THEN JUNAMT ELSE
IF JULAMT GT 0 THEN JULAMT ELSE
IF AUGAMT GT 0 THEN AUGAMT ELSE
IF SEPAMT GT 0 THEN SEPAMT ELSE
IF OCTAMT GT 0 THEN OCTAMT ELSE
IF NOVAMT GT 0 THEN NOVAMT ELSE DECAMT;



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
The buckets are in columns, so the problem is that,if for example FEBAMT was greater than zero, instead of ending, it still checks MARAMT therefore NEWAMT is then overstated.


Prod: WebFocus 7.7.3 Win 2003
Dev: WebFocus 7.7.3 Win 2003
quote:
NEWAMT/D6 =
IF JANAMT GT 0 THEN JANAMT ELSE
IF FEBAMT GT 0 THEN FEBAMT ELSE
IF MARAMT GT 0 THEN MARAMT ELSE
IF APRAMT GT 0 THEN APRAMT ELSE
IF MAYAMT GT 0 THEN MAYAMT ELSE
IF JUNAMT GT 0 THEN JUNAMT ELSE
IF JULAMT GT 0 THEN JULAMT ELSE
IF AUGAMT GT 0 THEN AUGAMT ELSE
IF SEPAMT GT 0 THEN SEPAMT ELSE
IF OCTAMT GT 0 THEN OCTAMT ELSE
IF NOVAMT GT 0 THEN NOVAMT ELSE DECAMT;


Donald, Francis's solution does what you want, except it should end

IF NOVAMT GT 0 THEN NOVAMT ELSE
IF DECAMT GT 0 THEN DECAMT ELSE 0;

IF - THEN - ELSE terminates processing as soon as a condition (either posative or negative) is met.
Donald,

You also may want to try and add the absolute value of each month together and check if that is zero.

Fernando


Prod WF 8.1.04, QA WF 8.2.03, Dev WF 8.2.03
JG,

Could you kindly explain why
NEWAMT/D6 =
IF JANAMT GT 0 THEN JANAMT ELSE
IF FEBAMT GT 0 THEN FEBAMT ELSE
IF MARAMT GT 0 THEN MARAMT ELSE
IF APRAMT GT 0 THEN APRAMT ELSE
IF MAYAMT GT 0 THEN MAYAMT ELSE
IF JUNAMT GT 0 THEN JUNAMT ELSE
IF JULAMT GT 0 THEN JULAMT ELSE
IF AUGAMT GT 0 THEN AUGAMT ELSE
IF SEPAMT GT 0 THEN SEPAMT ELSE
IF OCTAMT GT 0 THEN OCTAMT ELSE
IF NOVAMT GT 0 THEN NOVAMT ELSE DECAMT;

should be

NEWAMT/D6 =
IF JANAMT GT 0 THEN JANAMT ELSE
IF FEBAMT GT 0 THEN FEBAMT ELSE
IF MARAMT GT 0 THEN MARAMT ELSE
IF APRAMT GT 0 THEN APRAMT ELSE
IF MAYAMT GT 0 THEN MAYAMT ELSE
IF JUNAMT GT 0 THEN JUNAMT ELSE
IF JULAMT GT 0 THEN JULAMT ELSE
IF AUGAMT GT 0 THEN AUGAMT ELSE
IF SEPAMT GT 0 THEN SEPAMT ELSE
IF NOVAMT GT 0 THEN NOVAMT ELSE
IF DECAMT GT 0 THEN DECAMT ELSE 0; 

I see no reason for this. DECAMT could be greater than or equal to zero - my and your code will evaluate to the correct value.

Thanks,


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
FM -
I agree with (the other) JG. Donald expects a non-negaive result, and did not say that the buckets can't be negative. If (say) all 12 were neg, the result should be zero or missing, but not December's value.


- Jack Gross
WF through 8.1.05
Yup, you're right about negative values.

Cheers to both J.G.'s.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
Thanks everyone, it works well with the if-then and the ending condition of 0.


Prod: WebFocus 7.7.3 Win 2003
Dev: WebFocus 7.7.3 Win 2003