How to sum a field based on a condition in another field in RDLC report?
Asked Answered
C

3

10

I have an SQL database with skuno and qty columns, with the varchar(50) data type and an int data type respectively.

Here are the columns :

 skuno       qty
 -----------------
 78654   -   100  
 65495   -   120  
 10564   -   67  
 64389   -   20  

I want to sum qty where skuno begins with a "6" in rdlc report.

I am using this expression but getting an error :

=Sum(iif(Fields!skuno.Value like "6*", Fields!qty.Value, 0))

Where is the problem and how can I fix it?

Cortex answered 15/4, 2015 at 5:14 Comment(2)
@Matt Thrower It shows #Error in matrix data cell and not the calculated value...Cortex
Ah, so this is an excel question? Will change the tags if so, as all three are wrong in that case.Enchiridion
P
19

You can use an expression like this:

=Sum(CInt(IIf(Left(Fields!skuno.Value, 1) = "6", Fields!qty.Value, 0)))

Please note that you have to convert every possible values to the same type (CInt for Integer, CDec for Decimal, CDbl for Double, etc.) before aggregation.

Polymerize answered 15/4, 2015 at 13:32 Comment(1)
Thank you! The conversion to the same types makes a whole world of differenceDramaturgy
S
2
=Sum(IIf(Fields!HeaderModel.Value = 1 , cdbl(Fields!HeaderTAX.Value), 0), "DataSet2")
Scotfree answered 3/1, 2022 at 17:45 Comment(0)
T
0
=Sum(IIf(Fields!HeaderModel.Value = 1 , cdbl(Fields!HeaderTAX.Value), cdbl(0)), "DataSet2")
Thetes answered 16/2, 2022 at 14:40 Comment(2)
Your answer could be improved with additional supporting information. Please edit your answer to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Wingard
While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.Asyut

© 2022 - 2024 — McMap. All rights reserved.