Solved

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

Posted on 2014-04-24
6
336 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…

749 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