Solved

MS ACCESS 2007 syntax for an IIF "or".... /THEN statement that works in COGNOS

Posted on 2014-04-24
6
325 Views
Last Modified: 2014-05-28
Below isyntax porduces the correct info in COGNOS:
If ( [PM View prd].[DataTarget History].[Target] < [PM View prd].[Data].[Baseline] and [PM View prd].[Data].[Do we want to see an increase in this Measure?] = 0  or [PM View prd].[DataTarget History].[Target] > [PM View prd].[Data].[Baseline] and [PM View prd].[Data].[Do we want to see an increase in this Measure?] = 1 )
THEN ( [PM View prd].[DataTarget History].[Target] )
ELSE  (
[PM View prd].[Data].[Baseline] -  ([PM View prd].[Data].[Baseline] * .05  ) )
-------------------------------------------------------
Below is syntax I currently have in ACCESS that almost does the job.  However,it is missing the statement after the above COGNOS "or", and I have been unsuccessful at providing an acceptable syntax to make the report totally accurate:

TG: IIf([TmsrAmt]![Target]<[baseline],IIf([Do we want to see an increase in this Measure?]=False,[TmsrAmt]![Target],[baseline]-([baseline]*0.05)),[baseline]-([baseline]*0.05))
0
Comment
Question by:willjx
  • 3
  • 2
6 Comments
 
LVL 6

Expert Comment

by:Dulton
ID: 40021726
The cognos code seems to lack any parenthesis for cleanliness. I am surprised it returns the desired results. When you mix "And" and "Or", you'd better have parenthesis in order to establish your order of evaluation.

Regardless, the best way to get that much logic in access is to create a function.
I'm guessing at your datatypes, and set them to Decimal.
Public Function MyCognosLogic(Target As Decimal, Baseline As Decimal, _
                                                        SeeMeasure As Boolean) As Decimal

'Embed parenthesis in below If statement to partition your logic as desired.
If (Target < Baseline And _
    SeeMeasure = false Or _
    Target > Baseline And _
    SeeMeasure = true Then

            MyCognosLogic = Target
Else
            MyCognosLogic = Baseline - (Baseline * .05)      
End If
End Function

Open in new window


Once you've defined this in a module in your access file. reference it in your query by calling it like this:

TG: MyCognosLogic([TmsrAmt]![Target],[baseline],[Do we want to see an increase in this Measure?])
0
 

Author Comment

by:willjx
ID: 40027682
Unsatisfactory solution
0
 
LVL 1

Expert Comment

by:DexterFan
ID: 40072345
The following should work:

IIF([PM View prd].[DataTarget History].[Target] < [PM View prd].[Data].[Baseline] AND [PM View prd].[Data].[Do we want to see an increase in this Measure?] = 0, [PM View prd].[DataTarget History].[Target], IIF([PM View prd].[DataTarget History].[Target] > [PM View prd].[Data].[Baseline] AND [PM View prd].[Data].[Do we want to see an increase in this Measure?] = 1, [PM View prd].[DataTarget History].[Target], [PM View prd].[Data].[Baseline] -  ([PM View prd].[Data].[Baseline] * .05)))
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:willjx
ID: 40094276
Not quite.  
Both IIF statements produce the same result.  In My COGNOS statement noted above, you will notice an "OR"  which somehow needs to be included.
Your sugestion reproduced in ACCESS systax below does the same as my above noted ACCESS syntax:

TG: IIf([TmsrAmt]![Target]<[baseline] AND
[Do we want to see an increase in this Measure?]=0,
[TmsrAmt]![Target] ,

-------here i need:  
                  {on the other hand}  
{OR}


IIf([TmsrAmt]![Target]>[baseline] AND
[Do we want to see an increase in this Measure?]=1,
[TmsrAmt]![Target] ,
 [baseline]-([baseline]*0.05))
__________________
Below is the syntax you provided whch implies an "and" before the 2nd "IIF(...", when I need the syntax that will make it an "or" clause:

IIF([PM View prd].[DataTarget History].[Target] < [PM View prd].[Data].[Baseline] AND
[PM View prd].[Data].[Do we want to see an increase in this Measure?] = 0,
[PM View prd].[DataTarget History].[Target],

                  {on the other hand}  
{OR}

IIF([PM View prd].[DataTarget History].[Target] > [PM View prd].[Data].[Baseline] AND
[PM View prd].[Data].[Do we want to see an increase in this Measure?] = 1,
[PM View prd].[DataTarget History].[Target],
[PM View prd].[Data].[Baseline] - ([PM View prd].[Data].[Baseline] * .05)))
0
 
LVL 1

Accepted Solution

by:
DexterFan earned 500 total points
ID: 40094567
My understanding of OR is that either statement could be true.  You have asked to check if TARGET is less than BASELINE AND we don't want and increase, OR check if TARGET is greater than BASELINE AND we do want to see and increase.  If either statement is true then the result we want is the TARGET.  If both statements are FALSE, the we want to do a calculation with BASELINE.

My suggested code does the following

Check to see if TARGET is less than BASELINE and we don't want an increase.  If TRUE, the result is TARGET, if FALSE then check to see if TARGET is greater than BASELINE and we DO want to see an increase.  If TRUE then result is TARGET.  If FALSE the result is a calculation with BASELINE.  Have I missed something?
0
 

Author Closing Comment

by:willjx
ID: 40096536
Your logic was right.
I finnally got the ACCESS syntax needed to work by applying an appropriate (-) sign and an extra parenthesis:

TG: IIf([TmsrAmt]![Target]<[baseline] And [Do we want to see an increase in this Measure?]=0,[TmsrAmt]![Target],IIf([TmsrAmt]![Target]>[baseline] And [Do we want to see an increase in this Measure?]=-1,[TmsrAmt]![Target],[baseline]-([baseline]*0.05)))
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
Meetings to discuss business process can waste time, and often do .  The meeting's dialog can get confusing when participants have different professional perspectives and backgrounds.  A jointly-developed process picture helps wade through the confu…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now