Exclude Strings values for Totals Calculation in SSRS - reporting-services

I have question in SSRS report builder below is the data in column as
Site Information :
1,
2,
Not applicable.
So how to Calculate sum and percentage by excluding Not applicable text value .
Please help me

You can use the VAL() Function. This simply converts a string into a value is the string contains only data that can be viewed as a number.
So your expression would just be something like
=SUM(VAL(Fields!myTextField.Value))

Related

SSRS expression not working properly while using formatcurrency function

I have small expression on value fields in SSRS report. Source data type of value is NVARCHAR. It has some numeric value as well which I want to convert into currency and else should be display as it is.
=IIF(Fields!Description.Value LIKE "Blank*","",
IIF(IsNumeric(Fields!Value.Value)=True,FormatCurrency(Fields!Value.Value,0),Fields!Value.Value)
)
Report displays the numeric values in currency format but where it has string values it showing #Error.
I don't think you can use LIKE in an SSRS expression.. you need to use something like this:
=IIF(InStr(Fields!Description.Value,"Blank")>0,"",
IIF(IsNumeric(Fields!Value.Value)=True,FormatCurrency(Fields!Value.Value,0),Fields!Value.Value)
)

how to get last date between two dates SSRS

For Example i have two Parameters of Date
first: 1/21/2016
Second: 4/21/2017
I want to get second date.Is it possible through any SSRS Expression?
Yes. Assuming that the names of the parameters are First and Second, then you can access the values using the following expression.
=Parameters!First.Value
=Parameters!Second.Value
You can use this type of expression for any parameter, of any type, as long as you know the name.

sorting string numeric values in SSRS 2008

I have a varchar field (i am grouping on) in a dataset that returns a list of values : 20, 25, 40, 100, 110, 'N/A'..
I want the "numeric" values sorted from low to high : i.e : 20, 25...110, 'N/A'
the problem is that the A>Z sorting in the grouping gives out the following output :
100, 110, 25, ..., N/A
I cannot convert to numeric datatype since there are string values..
Does anyone have a solution please ?
Thank you in advance
Jam
There are several solutions you can implement here. I'll discuss the two I consider to be the easiest. If these don't work for you, let me know because there are a multitude of options. To make it easy, I've named the field you're referring to in your question as *num_text*.
Fix in SSRS:
Go to the Tablix Properties for the tablix displaying the data in question. Go to Sorting tab. Click Add. In the "Sort by" field, click the expression button and type the following:
=CInt(IIF(Fields!num_text.value = "N/A",9999999,Fields!num_text.value))
Note, you need to convert any possible text values to a number greater than any possible integer/decimal. In this case I chose 9999999 based on the examples in your question. If you have multiple text values that are not converted to number, Report Builder/BIDS will allow you to save the report, but when you render it, it will show #Error, signifying that the CInt (or any other conversion formula you choose) failed on a non-numeric value.
Fix in SQL:
Add a new field (like field_sort) with datatype numeric and use your case statement generating the current field in question saying:
, Case
When --Criteria leading to "N/A"
Then 9999999
Else num_text
End as field_sort
--Rest of SQL Script here
Order by field_sort
Then just display your num_text field in SSRS, and the values will be sorted properly. If you have many possible string values, then you might find it easier to fix in SQL (rather than specifying numerous IIF statements in SSRS.

SSRS: Get values from a particular row of DataSet?

My dataset currently has 12 rows of data. Each representing data for a month. I would like to have variance of a column between to rows, the rows being last & last but one i.e., latest month and previous month's data.
It could have been simple if I were to work on tablix but thats not the case. I want those values for a textbox.
Any ideas on it anyone?
I hope you are using SSRS 2008R2:
R2 introduced the Lookup function that is perfect for this scenario.
=Lookup( Fields!ProductUID.Value ,Fields!ProductID.Value,Fields!Price.Value,"PriceDataSet")
The Lookup function above will evaluate the first parameter ("Fields!ProductUID.Value") in the current dataset, then look for a matching value in the field specified in the second parameter ("Fields!ProductID.Value") in the dataset specified in the fourth parameter. The value of the third parameter is then evaluated in that row of the dataset and returned.
A little convoluted, but very helpful.
In your case, you can use this in a textbox with a calculated a static number:
=Lookup(
Month(DateAdd(DateInterval.Month, -1, GetDate())),
Fields!MonthID.Value,
Fields!Name.Value,
"DataSet1")
This should calculate a number for last month, then look for a match in DataSet1.
In this example I have a tablix with Statecode and name as below
enter image description here
Suppose you want to display the name of state of CA, write an expression as -
=Lookup(
"CA" ,
Fields!StateCode.Value,
Fields!StateName.Value,
"ReportData"
)
This will return 'California' in the text box
I ran across this post while trying to solve a similar problem but with columns of double data type. Not sure why but SSRS did not want to return my first row using LOOKUP in combination with ROW_NUMBER in SQL(If someone can solve that all the better). I ended up using a SUM(IIF) instead. Hopefully, this is useful for someone else.
=Sum(IIF(Fields!RowNum.Value=1,CDBL(Fields!MyNumericColumn.Value),CDBL(0)))
Note: If SSRS complains about data types, just cast both parts of the IIF to the desired data type.

how do i make addition of two fields in ssrs expression?

I have generated one ssrs report
now i have two fields having values
1st field value is =Fields!FirstNO.Value
2nd field value is =Fields!SecondNO.Value
now i have one field average and i need to write expression like
average = (Fields!FirstNO.Value+Fields!SecondNO.Value) / (Fields!SecondNO.Value)
how can i write above in expression?? directly as i shown or any other syntax is there please help?
Are you sure these fields are numeric? Maybe try convert to numeric, like =cint(Fields!FirstNO.Value)