I am near the end of a project. I have two final components to solve. I am hoping someone on the forum might have an idea as to how to solve on of them.
Here is my question: I have a rolling five years of data. My users select the last year and then they get to see that year, plus the previous five years.
At the end, we want to calculate two percentages of change.
The first one (PCTCHG1F) is basically the last year minus the previous year. If either field is 0, then it is masked and the formula provides a dash. Otherwise, the calculated percentage (from an earlier table) displays nicely.
That formula works beautifully.
The second formula (PCTCHG5F) does not work as well. It should be the current year minus the first year. If either the values of the first year and last year result in zeroes, they are masking appropriately with the caret. However, if the first year has a value but the last year is masked with a caret, the formula should behave just like the first formula and result in a dash. It's not.
I've tried using FST.
Is there a better way to do this? As an aside, I separated the COMPUTE statements below for ease in reading.
[CODE] TABLE FILE JDATA
COMPUTE ALPHAC_F/A15 =IF COUNTS3 EQ '0' THEN '^' ELSE ALPHAC;
-*Note the LAST takes into account the value for the max year less one. In other words, it returns the previous year's data correctly.
COMPUTE PCTCHG1F/A15 =IF LAST ALPHAC_F EQ '^' THEN '-' ELSE IF ALPHAC_F EQ '^' THEN '-' ELSE PCTCHG1ALPHA;
-*Is there a better way to account for the first instance of ALPHA_C_F? I am getting a value of 0% when the first value is masked. I want a dash when either the first year or last year is masked. I only want percentages when both have values.
COMPUTE PCTCHG5F/A15 =IF FST.ALPHAC_F EQ '^' THEN '-' ELSE IF ALPHAC_F EQ '^' THEN '-' ELSE PCTCHG5ALPHA;This message has been edited. Last edited by: JulieA,
FST only works in SUM, you could work around this by splitting data in a DEFINE e.g. IF YEAR EQ &firstYear THEN VALUE ELSE MISSING;
Test: WF 8.2
Prod: WF 8.2
DB: Progress, REST, IBM UniVerse/UniData, SQLServer, MySQL, PostgreSQL, Oracle, Greenplum, Athena.
An option is also not to try to do all in one step.
First, create the data as you need but with real numbers. Even if you have too many columns and non desired one, it's not important since it's an temp-step.
Second, use step one result to then add the masking option and only keep desired columns.
Often, trying to do all in one step make it more confusing and difficult to accomplish.
WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
Thank you both.
As to the suggestions: In the end, my solution utilized a missing component higher up in my procedure and then I continued it down below in the section I was asking about.
Again, thank you both. Something each of you said made the light bulb go off in my headThis message has been edited. Last edited by: JulieA,
|Powered by Social Strata|