Solved

How do I use IIF to Avg - Max Points!

Posted on 2010-11-17
13
345 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 29

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 29

Expert Comment

by:sammySeltzer
ID: 34159569
what do you want to show if negative?
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 29

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 29

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 29

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

A recent questions about how to add SSRS named instances, couldn't find any that talks about SQL server 2008, anyway I decided to help by creating some screen shots. The installation is straightforward, you just pop the SQL server 2008 installati…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
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…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 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