Solved

How do I use IIF to Avg - Max Points!

Posted on 2010-11-17
13
339 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
[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
  • 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Written by Valentino Vranken. Introduction: The first step of creating a SQL Server Reporting Services (SSRS) report involves setting up a connection to the data source and programming a dataset to retrieve data from that data source.  The data…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

740 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