Focal Point
[SOLVED] LAST function (sql intersect/recursive join)

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

February 09, 2016, 05:57 PM
Nicholas Spyrison
[SOLVED] LAST function (sql intersect/recursive join)
Potentially stupid question;

lets say I have:
Jan Feb Mar Aprl
units: 100 100 0 0

where I have 100 units for present and past months, and want to predict Units in the future with some basic math on a delta.
Expected Result:
Jan Feb Mar Aprl
units: 100 100 0 0
future: 100 100 105 110



If I use LAST units:
COMPUTE future/I3 = IF date LE today THEN units ELSE LAST units+delta;
Jan Feb Mar Aprl
units: 100 100 0 0
future: 100 100 105 5


If I LAST future:
COMPUTE future/I3 = IF date LE today THEN units ELSE LAST future+delta;
Jan Feb Mar Aprl
units: 100 100 0 0
future: 100 100 0 0


Am I missing a intersect command or something that I can use?

This message has been edited. Last edited by: Kathleen Butler,


_____
WF 8.1.04
Win 7// Windows Server 2012 R2
SASS OLAP Cube
February 09, 2016, 06:38 PM
BabakNYC
There's a FORECAST function in WF that does this type of stuff. Moving Average, single, double and triple exponential smoothing and Linear Regression. You can find the syntax for it in the documentation.


WebFOCUS 8206, Unix, Windows
February 10, 2016, 10:33 AM
Nicholas Spyrison
Oh, nice! I will have to look into that!

but for this case I have scheduled gains and loses that I want to apply (delta).

So I really need to carry Units@present into the future months


_____
WF 8.1.04
Win 7// Windows Server 2012 R2
SASS OLAP Cube
February 10, 2016, 01:39 PM
eric.woerle
Nicholas,

Can you post your actual code, or use the car file to create a sample. From what you wrote as your compute, it looks like the third option is correct. The problem might be in the way that you are ordering your data.

Thanks!


Eric Woerle
8.1.05M Gen 913- Reporting Server Unix
8.1.05 Client Unix
Oracle 11.2.0.2
February 10, 2016, 03:15 PM
Nicholas Spyrison
So I have it working with 3 computes to show 3 months out:

      COMPUTE future1/I6 = IF Date_Calendar_Month_YYYYMM LE &CURYM THEN Leased ELSE LAST Leased + Lease_Begin - Lease_End; OVER 
     COMPUTE future2/I6 = IF Date_Calendar_Month_YYYYMM LE &FUTURE1 THEN future1 ELSE LAST future1 + Lease_Begin - Lease_End; OVER 
     COMPUTE future3/I6 = IF Date_Calendar_Month_YYYYMM LE &FUTURE2 THEN future2 ELSE LAST future2 + Lease_Begin - Lease_End; OVER  


I thought that it didn't like the recursive reference, but I have CAR working using the recursive;

 TABLE FILE IBISAMP/CAR
SUM 
     MPG
     COMPUTE CUMMULATIVE_MPG/D6 = MPG + LAST CUMMULATIVE_MPG;
BY  CAR
END
 



_____
WF 8.1.04
Win 7// Windows Server 2012 R2
SASS OLAP Cube
February 10, 2016, 04:00 PM
eric.woerle
What are your BY fields? It could have to do with the way you have organized those.

As you've noticed the problem isn't in the recursiveness of the statement since you have it working as expected with the car file.

At this point I think the best way for us to give you answers is for you to post your code. We can probably find your issue pretty fast if you do that.


Eric Woerle
8.1.05M Gen 913- Reporting Server Unix
8.1.05 Client Unix
Oracle 11.2.0.2
February 10, 2016, 04:03 PM
eric.woerle
The problem could also be in your fields TODAY and DATE. What format are they? Are they actually YYM? or are they Alphas for April May June etc? Its possible that the comparison is failing, giving you unites instead of FUTURE + DELTA....


Eric Woerle
8.1.05M Gen 913- Reporting Server Unix
8.1.05 Client Unix
Oracle 11.2.0.2
February 11, 2016, 02:35 AM
Tony A
Are you using ACROSS and expecting LAST to relate to the previous column (and therefore not row)?

If so, then that is your issue.

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 
February 11, 2016, 11:53 AM
Nicholas Spyrison
TABLE FILE LAHOLD1
SUM
     Notice_For_Move_Out AS 'Notice For Move Out' OVER
     Skipped_Lease AS 'Skipped Lease' OVER
     Eviction_Count AS 'Eviction Count' OVER
     Lease_End AS 'Leases Expire' OVER
     LEASE_BEGIN_NEW_LEASE AS 'Leases Begin - New Leases' OVER
     LEASE_BEGIN_RENEWAL AS 'Leases Begin - Renewal' OVER
     Lease_Begin AS 'Leases Begin - Total' OVER
     COMPUTE RENEWAL_RATIO_PCT/D12.2% = 100 * Renewal_Ratio__; AS 'Renewal Ratio %' OVER
     Leased/I6 OVER
     COMPUTE future1/I6 = IF Date_Calendar_Month_YYYYMM LE &CURYM THEN Leased ELSE LAST Leased + Lease_Begin - Lease_End; OVER
     COMPUTE future2/I6 = IF Date_Calendar_Month_YYYYMM LE &FUTURE1 THEN future1 ELSE LAST future1 + Lease_Begin - Lease_End; OVER
     COMPUTE future3/I6 = IF Date_Calendar_Month_YYYYMM LE &FUTURE2 THEN future2 ELSE LAST future2 + Lease_Begin - Lease_End; OVER
     Vacant OVER
     Units/I7 OVER
     Left_To_Lease AS 'Left To Lease'
ACROSS LOWEST Date_Calendar_Month_YYYYMM NOPRINT  AS 'YYYYMM'
ACROSS LOWEST Date_Calendar_Month_YYYYMM AS 'Month'


Dates, and &var are I6. IE) &CURYM = 201602.

Tony may have it. I am displaying across Month and I want to go to the last month's value.

I know having 3 computes isn't optimal, but is there strong argument against using the 3 computes and showing the 3rd one?


_____
WF 8.1.04
Win 7// Windows Server 2012 R2
SASS OLAP Cube
February 12, 2016, 03:17 PM
eric.woerle
Nicholas,

Use a hold file. The order of the data is extremely important when using last. Make your dates BY fields and remove the overs. Hold the data and then put your across back in. like this:

 
TABLE FILE LAHOLD1
SUM
     Notice_For_Move_Out
     Skipped_Lease 
     Eviction_Count 
     Lease_End 
     LEASE_BEGIN_NEW_LEASE 
     LEASE_BEGIN_RENEWAL 
     Lease_Begin
     COMPUTE RENEWAL_RATIO_PCT/D12.2% = 100 * Renewal_Ratio__;
     Leased/I6 
     COMPUTE future1/I6 = IF Date_Calendar_Month_YYYYMM LE &CURYM THEN Leased ELSE LAST Leased + Lease_Begin - Lease_End; 
     COMPUTE future2/I6 = IF Date_Calendar_Month_YYYYMM LE &FUTURE1 THEN future1 ELSE LAST future1 + Lease_Begin - Lease_End; 
     COMPUTE future3/I6 = IF Date_Calendar_Month_YYYYMM LE &FUTURE2 THEN future2 ELSE LAST future2 + Lease_Begin - Lease_End; 
     Vacant 
     Units/I7 
     Left_To_Lease 
BY LOWEST Date_Calendar_Month_YYYYMM 
ON TABLE HOLD AS LAHOLD2
END
TABLE FILE LAHOLD2
SUM
     Notice_For_Move_Out AS 'Notice For Move Out' OVER
     Skipped_Lease AS 'Skipped Lease' OVER
     Eviction_Count AS 'Eviction Count' OVER
     Lease_End AS 'Leases Expire' OVER
     LEASE_BEGIN_NEW_LEASE AS 'Leases Begin - New Leases' OVER
     LEASE_BEGIN_RENEWAL AS 'Leases Begin - Renewal' OVER
     Lease_Begin AS 'Leases Begin - Total' OVER
     RENEWAL_RATIO_PCT OVER
     Leased/I6 OVER
     future1 OVER
     future2 OVER
     future3 OVER
     Vacant OVER
     Units/I7 OVER
     Left_To_Lease AS 'Left To Lease'
ACROSS LOWEST Date_Calendar_Month_YYYYMM NOPRINT  AS 'YYYYMM'
ACROSS LOWEST Date_Calendar_Month_YYYYMM AS 'Month'
END
 



Eric Woerle
8.1.05M Gen 913- Reporting Server Unix
8.1.05 Client Unix
Oracle 11.2.0.2
February 17, 2016, 05:48 PM
Nicholas Spyrison
Eric is right. best method is to order carefully, and use LAST only with BY fields. If needed, HOLD and use ACROSS

Thanks all!


_____
WF 8.1.04
Win 7// Windows Server 2012 R2
SASS OLAP Cube