I have an SSRS report where I want to count specific results from the larger query (Overall Total - then of those total "Open" and total "Closed"). I'm trying to use the expression:
=CountDistinct(IIF(Fields!CaseStatusCode.Value='OPEN', Fields!CaseID.Value, Nothing))
But whenever I run the report I get:
There is a syntax error in the Value expression for the textrun ‘Textbox24.Paragraphs[0].TextRuns[0]’: ‘)’ expected.
I've added and removed multiple ) but the error persists. I've also tried the expression in different textboxes and the error continues (just changing the name of the textbox it's in). What am I missing?
Solved it. Apparently I am supposed to use " instead of '. Corrected code below.
=CountDistinct(IIF(Fields!CaseStatusCode.Value="OPEN", Fields!CaseID.Value, Nothing))
Related
Hello I'm fairly new to SSRS and I'm working on making my first report for work. It has been going fine until today when I needed make a textbox in Tablix handle both a numbers calculation and text. A column in my SQL table that was previously a purely number field now has n|a for certain rows. So I wrote the following expression to handle those n|as. When the proceeds field is numeric the formula works, but when it's an n|a it shows up on the report as #error and I can't figure out why. I've removed all formatting from the textbox to the same result.
=IIF(Fields!Proceeds.Value<>"n|a",Fields!Proceeds.Value / Fields!DealBalance.Value,"n|a")
As TnTinMn explained, IIF always evaluates both the true and false part of the expression.
The simple fix is to do something like
EDIT Revised due to update from OP
=IIF(Fields!Proceeds.Value<>"n|a",VAL(REPLACE(REPLACE(Fields!Proceeds.Value,",",""),"$","")) / Fields!DealBalance.Value,"n|a")
This simply strips out the $ symbol and commas and then converts the text to a number using VAL(), if the text is not a number it will return zero which will not cause an error as the false part of your expression would give 0/DealBalance.
I'm creating a report in Reporting Services to display time-spans for classroom sessions in our program. One column that was requested is to show the total number of hours between the start and end time of one session. I used a DATEDIFF function showing the DateInterval in hours as the total hours in one time-span, but I get a #Error returned for the blank values that haven't been assigned a begin or end time.
I added an IIF statement to mark the values that are blank as "TBA", but that didn't work. Since I'm casting a string to a datetime value, I enclosed the DATEDIFF statement in a CStr function, but that also isn't working. Lastly, I did the simple thing and set the text box to display a Number value since it's returning the total number of hours, but of course, that didn't work either. My code is as follows:
=IIF(Fields!BeginTime.Value = "", "TBA", CStr(DateDiff(DateInterval.Hour, Fields!BeginTime.Value, Fields!EndTime.Value)))
It's supposed to show that "TBA" value in the blank spots, but I still get a #Error. The total hours are coming up fine for the values that aren't blank, however. I checked the value in the dataset to see if it's returning a blank or a NULL-labeled value, and it is returning a blank value.
I believe the issue is arising in the conditional statement. If Fields!BeginTime.Value is a date datatype, comparing it to "" will likely result in the error you're getting. I suggest using the IsNothing function or just checking if the field is nothing. The two options are as follows.
=IIF(IsNothing(Fields!BeginTime.Value), ...
Or...
=IIF(Fields!BeginTime.Value Is Nothing, ...
With that said, you shouldn't need to use the CStr as DateDiff will return an integer value. Your textbox should be set to Default or some text variant to prevent errors there. The expression will return either an integer or string so a number format on the textbox will not work.
Additionally, if you're having the same issue when there is no EndTime, you may want to add an OR to the conditional to fix that.
=IIF(IsNothing(Fields!BeginTime.Value) OR IsNothing(Fields!EndTime.Value), ...
I am having an issue summing a column of dollar amounts in a DataTable with VB. I have tried two different ways resulting in two different errors which I am not sure how to resolve. Before I go into the two ways I have tried to solve the problem here is the setup:
I am importing a tab delimited file into a DataTable. The headers are automatically populated with data from the first row in the file.
The DataGridView that displays the Datatable is called DGV_detail.
The column in DGV_detail I am trying to sum occurs at column 3 and is called 'Value-to-date'. This column is full of dollar amount values similar to: $10.00 With the dollar sign and everything.
I am also declaring a view variables and doing some calculations when a button is clicked.
Here is my first approach:
For i As Integer = 0 To DGV_detail.Rows.Count() - 1 Step +1
interestPaidToAccounts = interestPaidToAccounts + DGV_detail.Rows(i).Cells(3).Value
Next
When I try this approach I get the following error:
An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
Conversion from string "" to type 'Double' is not valid.
The other methods I was trying to use to solve the problem were (For reference: In these examples I created a variable local to the button_click function that assigned the BGV_detail.DataSource to equal dataTable1):
Dim sumObject = dataTable1.Compute("Sum(Convert(Value-to-date, 'System.Decimal'))", "[Value-to-date] IS NOT NULL")
and
Dim sumObject As Decimal = dataTable1.Compute("Sum(Value-to-date)", "")
Which both produced the following error:
Expecting a single column argument with possible 'Child' qualifier.
I am pretty lost at this point so whatever the community thinks the best method to resolves these problems is, I am open to.
I can provide additional information if needed! :)
Thanks in advance for your help!
The dollar sign is the issue, use mid to remove it and val to convert to number:
val(mid(DGV_detail.Rows(i).Cells(3).Value, 2,DGV_detail.Rows(i).Cells(3).Value.length -1))
Untested, but should get you started ... there are any number of ways to remove the $.
Im getting error for the below expression in rdlc. what is causing error
=IIf(Fields!Name.Value Like "PL*","STREET INTERSECTION","STREET SEGMENT")
the requirement is the value of the text box should be dynamic depending on the item Name("Name" field). If the item Name starts with PL, this value should be "STREET INTERSECTION" if name starts with PS , this Value should be "STREET SEGMENT".
This will work for you.
SSRS supports VBA functionality rather SQL function / syntax.
=IIf(Fields!Name.Value.IndexOf("PL") >= 0,"STREET INTERSECTION","STREET SEGMENT")
In a rdlc report i'm using an expression to hide the row visibility.
If the expression is true the row is hidden.
The value of the field can be "Ja", "Nee" or Null. Only if it's "Ja" the row must be shown and the expression result should be false.
The expression
=Iif(Fields!Vleugel.Value Is Nothing,true,false)
is working but when I want to add the "Ja" condition like:
=Iif(Fields!Vleugel.Value Is Nothing,true,Iif(Fields!Vleugel.Value.Equals("Ja"),false,true))
it's causing an error like "Object reference not set to an instance of an object." when the field is null.
Can't figure out what's wrong since it's looks simular to examples I found.
If you use the Row Visilibily property you don't have to write an iif statement, it is enough to give the expression that will hide the row, try this:
=Fields!Vleugel.Value Is Nothing