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
Solved

How do I use IIF to Avg - Max Points!

Posted on 2010-11-17
13
332 Views
Last Modified: 2012-05-10
How do I rewrite this expression so that it ignores negitive numbers and zeros but will not return NaN... the expression below works great however if I change it to <>0 it returns NaN
= IIF(Fields!Profit.Value=0,nothing,(Fields!.Value/Fields!.Value))

Open in new window

0
Comment
Question by:SPLady
  • 5
  • 5
  • 3
13 Comments
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 34159118


Try this

= IIF(IsNothing(Fields!Profit.Value),0,Fields!.Value)/IIf(IsNothing(Fields!.Value) Or Fields!.Value=0,1,Fields!.Value)

0
 
LVL 1

Author Comment

by:SPLady
ID: 34159398
Thank you @sammySeltzer I cant get it to work, I am lost on the denominator (bottom) part... below is the actual expression
IIF(Fields!InvoiceAmount_CurrentYear.Value=0,nothing,(Fields!ShipmentProfit.Value/Fields!InvoiceAmount_CurrentYear.Value))

Open in new window

0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 34159569
what do you want to show if negative?
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 28

Expert Comment

by:sammySeltzer
ID: 34159571
and what error did you get with the code I posted?
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34159631
Try changing from =0 to <= 0, so that if it is negative or 0, it goes to "nothing"

The problem with <>0 is that it causes divide by 0 on the right side
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 34159648
Try this.
Run this function

Public Shared Function Ratio(Num1 as double, Num2 as double) AS object
    IF ISNOTHING(Num2) Or Num2 = 0 Then
        Ratio = 0
    ELSEIF Num1 = 0 THEN
        Ratio = 0
    ELSE
        Ratio = Num1  / Num2
    END IF
End Function 

Open in new window


Then use this code to invoke the function:

=Code.Ratio(Fields!InvoiceAmount_CurrentYear.Value, Fields!ShipmentProfit.Value/Fields!InvoiceAmount_CurrentYear.Valu)

Open in new window

0
 
LVL 1

Author Comment

by:SPLady
ID: 34159769
Ok I put the function in the report properties> code and I put the "invoker" in the expression... correct?

if so it indicates that the ratio portion is an unidentified expression

=Code.Ratio(Fields!InvoiceAmount_CurrentYear.Value, Fields!ShipmentProfit.Value/Fields!InvoiceAmount_CurrentYear.Valu)

0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34159789
Hi splady

"How do I rewrite this expression so that it ignores negitive numbers and zeros but will not return NaN... the expression below works great however if I change it to <>0 it returns NaN"

Do you want to turn
(1) a [final] result of -ve to 0, e.g. what the [working] IIF would return as-is right now?
or
(2) change the IIF such that the first condition ignores negative and 0? It currently doesn't perform the ratio for 0 [only], but that is only because the ratio of x/0 is undefined.  You cannot divide by 0.
0
 
LVL 1

Author Comment

by:SPLady
ID: 34159851
I want the final result to be nothing or greater that Zero
0
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
ID: 34159962
=IIF(Fields!Profit.Value=0,nothing,IIF(Fields!.Value/Fields!.Value)<=0,nothing,Fields!.value/Fields!.Value))

basically, for the 3rd part, wrap it in another IIF, test it for <= 0, and output either nothing or the 3rd part
0
 
LVL 1

Author Closing Comment

by:SPLady
ID: 34160053
Thank You!
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 34161037
hi SPLady,

Even though the thread is closed, I wanted to show you why you got undefined expression:

Fields!ShipmentProfit.Value/Fields!InvoiceAmount_CurrentYear.Valu)


Notice that I copied Fields!InvoiceAmount_CurrentYear.Valu but mistakenly cut off e.

So instead of Fields!InvoiceAmount_CurrentYear.Valu
e
I pasted Fields!InvoiceAmount_CurrentYear.Valu

sorry about that.
0
 
LVL 1

Author Comment

by:SPLady
ID: 34163819
@sammySeltzer, thanks soo much, I missed that!
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

837 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