?
Solved

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

Posted on 2014-04-24
6
Medium Priority
?
341 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
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 

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 1500 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.
Suggested Courses

752 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