Solved

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

Posted on 2014-04-24
6
331 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As freelancing is becoming more and more common in the tech industry, certain obstacles are proving to be a challenge to those who are used to more traditional, structured employment. This article is meant to help identify such obstacles and offer a…
A high-level exploration of how our ever-increasing access to information has changed the way we do our jobs.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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…

770 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