SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


iif Statement Help


iif Statement Help

Author
Message
Sprout
Sprout
Grasshopper
Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)

Group: General Forum Members
Points: 17 Visits: 102
I'm attempting to add field DrAmt based on field TranType. So when TranType = "INT" then add the value in DrAmt. Here is my statement:
=iif(Fields!TrantypeID.Value = "INT",SUM(Fields!DrAmt),0)

When I run the report I receive this error:
[rsAggregateOfInvalidExpressionDataType] The Value expression for the textrun ‘textbox76.Paragraphs[0].TextRuns[0]’ uses an aggregate function with an expression that returned a data type not valid for the aggregate function

Any help would be appreciated.

Thanks.
Ray M
Ray M
SSCertifiable
SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)

Group: General Forum Members
Points: 5141 Visits: 1076
I think there's an error in your expression. Are you missing the .Value? (Bolded below)
=iif(Fields!TrantypeID.Value = "INT",SUM(Fields!DrAmt.Value),0)
Sprout
Sprout
Grasshopper
Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)

Group: General Forum Members
Points: 17 Visits: 102
Oh yeah that would help. Thanks, but the expression does not return the correct value just zero. I know there there data it should be calculating. Any ideas??
Ray M
Ray M
SSCertifiable
SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)

Group: General Forum Members
Points: 5141 Visits: 1076
Looking at your dataset, what values are in the tranTypeID?
Is there actually a value called 'INT'?
Sprout
Sprout
Grasshopper
Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)

Group: General Forum Members
Points: 17 Visits: 102
Yes the vaules are INT, DEP, WHT
Ray M
Ray M
SSCertifiable
SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)

Group: General Forum Members
Points: 5141 Visits: 1076
I think this will help.
Try wrapping the sum outside the iif
=SUM(iif(Fields!TrantypeID.Value = "INT",Fields!DrAmt,0))
Sprout
Sprout
Grasshopper
Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)

Group: General Forum Members
Points: 17 Visits: 102
Still zero amount.
Ray M
Ray M
SSCertifiable
SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)

Group: General Forum Members
Points: 5141 Visits: 1076
Weird, its gotta be something silly.

Can you post a small sample of your dataset.
It seems fishy that the field your looking is named TranTypeID.Value, but your comparing it to Text value of 'INT'
Sprout
Sprout
Grasshopper
Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)Grasshopper (17 reputation)

Group: General Forum Members
Points: 17 Visits: 102
Here is an example of the data:

TranTypeID DrAmt CrAmt
CHK 0.00 13.37
CHK 0.00 22.50
ACHO 0.00 10.12
WD 0.00 35.00
CHK 0.00 125.00
CHK 0.00 60.23
DEP 25.00 0.00
INT 42.30 0.00
CHK 0.00 85.30
CHK 0.00 100.00
INT 200.00 0.00
Ray M
Ray M
SSCertifiable
SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)

Group: General Forum Members
Points: 5141 Visits: 1076
Are you grouping by Something else? Feels like something is missing.
Check the attached test Report1, on a row by row basis, the expression is reflecting the amt correctly, so Not sure what the issue is.
Attachments
Report1.zip (7 views, 1.00 KB)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search