0

Okay so I am trying to do math in this IIF statement in reportviewer. However, all it does is return FALSE in my field. Am I able to do math with an IIF statement or what?

=IIF(
     UCase(Fields!Tax.Value) = "YES", 
     Variables!DeptTotal.Value =+(Fields!TotalPriceWithoutTax.Value * (1 + Parameters!Tax.Value)), 
     Variables!DeptTotal.Value =+ (Fields!TotalPriceWithoutTax.Value)
     )

Any Ideas? Thanks in advance.

EDIT:

Okay Guys,

I even did a custom codes and it still returns false.

Public Function Taxable(Answer AS String, DepartTotal AS Decimal, TotalWithoutTax AS Decimal, Tax AS Decimal) AS Decimal

    If UCase(Answer) = "YES" Then

         DepartTotal += TotalWithoutTax * Tax 

    Else

       DepartTotal +=  TotalWithoutTax

    End If

    Return DepartTotal

End Function

Any other sugguestions?

Thanks Again.

EDIT:

This is my taxable function call:

=Code.Taxable(Tax, DepartTotal, TotalWithoutTax, txtTax.value)
daniel.porter
  • 101
  • 2
  • 13
  • 1
    I am not sure how related this is, but since you use side effects on both "yes" and "no" sides, you may want to read [this link](http://stackoverflow.com/q/1220411/335858). Summary of the linked question: both "yes" and "no" expressions are *always* evaluated. – Sergey Kalinichenko Jan 15 '13 at 21:16
  • In short, use `If()` not `Iif()` unless you're really sure you need to. Even then, it's not advised as it is currently marked as deprecated. – Origin Jan 15 '13 at 21:22
  • How would you use IF()? I get a compile error. – daniel.porter Jan 15 '13 at 21:41
  • Since your Taxable function returns a **Decimal** type, it cannot possibly return False (a **Boolean**). Can you show us how you are calling the Taxable function? – Chris Dunaway Jan 16 '13 at 15:48

3 Answers3

0

UCase(Fields!Tax.Value) = "YES", Tax.value may return false and true or 0 and 1 , test it again and good luck.

AbdElrhman
  • 52
  • 2
0

Try this: change =+ to +=

Change

Variables!DeptTotal.Value =+(Fields!TotalPriceWithoutTax.Value * (1 + Parameters!Tax.Value))

to

Variables!DeptTotal.Value += (Fields!TotalPriceWithoutTax.Value * (1 + Parameters!Tax.Value))
codingbiz
  • 26,179
  • 8
  • 59
  • 96
0

This is the fix:

The function:

Public Function Taxable(Answer AS String, TotalWithoutTax AS Decimal, Tax AS Decimal) AS Decimal

       Dim total AS Decimal = 0

       If UCase(Answer) = "YES" Then

             total = TotalWithoutTax *  (1 + Tax)

        Else
             total = TotalWithoutTax

        End If

        Return total

End Function

The Call:

Code.Taxable(Fields!Tax.Value, Sum(Fields!TotalPriceWithoutTax.Value), Parameters!Tax.Value)
daniel.porter
  • 101
  • 2
  • 13