Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Using the LAST Function

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] Using the LAST Function
 Login/Join
 
Platinum Member
posted
I am trying to create a column of data that has the difference between numeric format field value on the current record to the one on the previous record with the code below.

The PRVDELTA define correcly returns the previous record's value. However, the PRVDELTA2 define does not return previous record's value that corresponds with PRVDELTA.

Am I using the LAST Function correctly?

TABLE FILE BASELINE2
SUM
CT_DAYS AS 'CT_DAYS' 

BY SRT_MONTH AS 'SRT_MONTH'

ON TABLE HOLD AS 'BASELINE3'
END 


DEFINE FILE BASELINE3
PRVDELTA/YYMD= IF SRT_MONTH EQ LAST SRT_MONTH THEN SRT_MONTH ELSE LAST SRT_MONTH;
PRVDELTA2/I8= IF SRT_MONTH EQ LAST SRT_MONTH THEN CT_DAYS ELSE LAST CT_DAYS;
END

TABLE FILE BASELINE3
PRINT
SRT_MONTH AS 'Month'
CT_DAYS AS 'Cycle Days' 
PRVDELTA AS 'Previous Month'
PRVDELTA2 AS 'Previous Month Cycle Days'

BY SRT_MONTH NOPRINT

ON TABLE SET STYLE *
TYPE=DATA, COLUMN=N2, BACKCOLOR=BLUE, WHEN=CT_DAYS LT 14,$
TYPE=DATA, COLUMN=N2, BACKCOLOR=LIME, WHEN=CT_DAYS LT 19,$
TYPE=DATA, COLUMN=N2, BACKCOLOR=YELLOW, WHEN=CT_DAYS LT 24,$
TYPE=DATA, COLUMN=N2, BACKCOLOR=RED, WHEN=CT_DAYS GT 25,$
ENDSTYLE

ON TABLE SET HTMLCSS ON
ON TABLE SET PAGE-NUM OFF
ON TABLE NOTOTAL
END
-EXIT

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


Production - 7.6.4
Sandbox - 7.6.4
 
Posts: 241 | Location: Bethesda, MD | Registered: August 14, 2007Report This Post
Expert
posted Hide Post
DEFINE FILE BASELINE3
PRVDELTA/YYMD= IF SRT_MONTH EQ LAST SRT_MONTH THEN PRVDELTA ELSE LAST SRT_MONTH;
PRVDELTA2/I8= IF SRT_MONTH EQ LAST SRT_MONTH THEN PRVDELTA2 ELSE LAST CT_DAYS;
END

Try this instead.


Ginny
---------------------------------
Prod: WF 7.7.01 Dev: WF 7.6.9-11
Admin, MRE,self-service; adapters: Teradata, DB2, Oracle, SQL Server, Essbase, ESRI, FlexEnable, Google
 
Posts: 2723 | Location: Ann Arbor, MI | Registered: April 05, 2006Report This Post
Platinum Member
posted Hide Post
That returnsthe following, which is still out of sync (look at the right hand column).

Month      Cycle Days      Previous Month      Previous Month Cycle Days 
2009/01/31 23                                  0 
2009/02/28 25              2009/01/31          22 
2009/03/31 20              2009/02/28          25 
2009/04/30 22              2009/03/31          20 
2009/05/31 19              2009/04/30          21 
2009/06/30 20              2009/05/31          18 
2009/07/31 24              2009/06/30          19 
2009/08/31 16              2009/07/31          23 
2009/09/30 17              2009/08/31          16 
2009/10/31 23              2009/09/30          17 
2009/11/30 26              2009/10/31          22 
2009/12/31 22              2009/11/30          26 


Production - 7.6.4
Sandbox - 7.6.4
 
Posts: 241 | Location: Bethesda, MD | Registered: August 14, 2007Report This Post
Expert
posted Hide Post
PRVDELTA/YYMD= IF SRT_MONTH NE LAST SRT_MONTH THEN LAST SRT_MONTH ELSE PRVDELTA;
PRVDELTA2/I8= IF SRT_MONTH NE LAST SRT_MONTH THEN LAST CT_DAYS ELSE PRVDELTA2;

Try this. I always do my NE logic first as it makes more sense to me to figure out what I want to do on the sort break.


Ginny
---------------------------------
Prod: WF 7.7.01 Dev: WF 7.6.9-11
Admin, MRE,self-service; adapters: Teradata, DB2, Oracle, SQL Server, Essbase, ESRI, FlexEnable, Google
 
Posts: 2723 | Location: Ann Arbor, MI | Registered: April 05, 2006Report This Post
Virtuoso
posted Hide Post
Also try try throwing in a sort on CT_DAYS
 
Posts: 1903 | Location: San Antonio | Registered: February 28, 2005Report This Post
Expert
posted Hide Post
The data is already sorted by month so you don't need to do that. I did a prototype and verified my define code before I posted it.


Ginny
---------------------------------
Prod: WF 7.7.01 Dev: WF 7.6.9-11
Admin, MRE,self-service; adapters: Teradata, DB2, Oracle, SQL Server, Essbase, ESRI, FlexEnable, Google
 
Posts: 2723 | Location: Ann Arbor, MI | Registered: April 05, 2006Report This Post
Guru
posted Hide Post
The LAST function seems to pickup the previous cycle days, except sometime gives (previous-days - 1)???


Developer Studio 7.6.11
AS400 - V5R4
HTML,PDF,XLS
 
Posts: 305 | Location: Winnipeg,MB | Registered: May 12, 2008Report This Post
Virtuoso
posted Hide Post
I suspect that the data in BASELINE3 is not as you are expecting, reason unknown. Your use of LAST is fine if the data coming in is correct. Try
TABLE FILE BASELINE3
SUM
           SRT_MONTH               AS 'Month'
           CT_DAYS                 AS 'Cycle Days' 
COMPUTE 
PRVDELTA/YYMD = IF SRT_MONTH EQ LAST SRT_MONTH THEN SRT_MONTH ELSE LAST SRT_MONTH; 
                                   AS 'Previous Month'
COMPUTE 
PRVDELTA2/I8 = IF SRT_MONTH EQ LAST SRT_MONTH THEN CT_DAYS ELSE LAST CT_DAYS; 
                                   AS 'Previous Month Cycle Days'
BY         SRT_MONTH               NOPRINT
END

and see what happens.


Alan.
WF 7.705/8.007
 
Posts: 1451 | Location: Portugal | Registered: February 07, 2007Report This Post
Platinum Member
posted Hide Post
This gives me the same results. Does that mean that it is something wrong with the code that creates the BASELINE3 hold file?


Production - 7.6.4
Sandbox - 7.6.4
 
Posts: 241 | Location: Bethesda, MD | Registered: August 14, 2007Report This Post
Expert
posted Hide Post
Did you use the defines in my last post. I tested those with your data and got the right answers.

It appears to me that your data is correct. It must be sorted by SRT_MONTH and there is only one row per month. That is what I determine from your code.


Ginny
---------------------------------
Prod: WF 7.7.01 Dev: WF 7.6.9-11
Admin, MRE,self-service; adapters: Teradata, DB2, Oracle, SQL Server, Essbase, ESRI, FlexEnable, Google
 
Posts: 2723 | Location: Ann Arbor, MI | Registered: April 05, 2006Report This Post
Guru
posted Hide Post
I wonder what will this give you?
PRVDELTA/YYMD= LAST SRT_MONTH ;
PRVDELTA2/I8= LAST CT_DAYS;



Hua


Developer Studio 7.6.11
AS400 - V5R4
HTML,PDF,XLS
 
Posts: 305 | Location: Winnipeg,MB | Registered: May 12, 2008Report This Post
Platinum Member
posted Hide Post
Ginny -

I greatly appreciate your help. I used your defines. It appears to be working correctly for the previous month column, but not the cycle days column.

For example, on the results I got above, the February record correctly shows that the previous month is January, but on the February row, the Previous Month (January) cycle days do not match the january record from above.

What would cause LAST to work for one field, but not the other? Field format? Sorting?


Production - 7.6.4
Sandbox - 7.6.4
 
Posts: 241 | Location: Bethesda, MD | Registered: August 14, 2007Report This Post
Expert
posted Hide Post
CWM,

To be sure that you are using the correct LAST operation that matches your sort requirement, use COMPUTE within the TABLE request as per Alan above.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
 
Posts: 5694 | Location: United Kingdom | Registered: April 08, 2004Report This Post
Platinum Member
posted Hide Post
Even when I use the COMPUTE, I get this:

Month      Cycle Days Previous Month Previous Month Cycle Days 
2009/01/31 23                        0 
2009/02/28 25         2009/01/31     22 
2009/03/31 20         2009/02/28     25 
2009/04/30 22         2009/03/31     20 
2009/05/31 19         2009/04/30     21 


The January cycle days for row 1 & row 2 do not match, but should.

However, the February cycle days for row 2 & row 3 do? match.

Why does it only return the correct data sometimes?


Production - 7.6.4
Sandbox - 7.6.4
 
Posts: 241 | Location: Bethesda, MD | Registered: August 14, 2007Report This Post
Expert
posted Hide Post
As Hua suggested; also, use SUM instead of PRINT:
COMPUTE 
PRVDELTA2/I8 = LAST CT_DAYS; AS 'Previous Month Cycle Days'


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
 
Posts: 1972 | Location: Centennial, CO | Registered: January 31, 2006Report This Post
Platinum Member
posted Hide Post
Solved it!

The problem was not with the DEFINE itself, or the compute.

The problem was being caused by the PRVDELTA2 field formatting being I8, but the CT_DAYS was formatted as D8S. Once I made PRVDELTA2 to a D8S format, it fixed the problem.

Thank you all for your help with this.

-CWM


Production - 7.6.4
Sandbox - 7.6.4
 
Posts: 241 | Location: Bethesda, MD | Registered: August 14, 2007Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Using the LAST Function

Copyright © 1996-2020 Information Builders