I use the following expression to obtain a row number for a table in SSRS:
=RunningValue(CountDistinct("Table1"),Count,"Table1")
I also use an expression for the row visibility property. Lets just say that the Visibility expression is
=IIf(Fields!MyField.Value + Fields!MyField.Value <> 0, False, True)
My expression for the row number does not consider if the row is visible or not.
I could obviously change my dataset query, but is it possible to just alter my Row Number expression to only include rows that aren't hidden?
Thanks
You can probably achieve this by combining the logic of your two expressions.
Say you have a simple DataSet and a simple Tablix based on this:
Here, RowNum is calculated as:
=RunningValue(Fields!val1.Value, CountDistinct, "Tablix1")
Next, let's hide some rows using an expression based on the other two fields:
=IIf(Fields!val2.Value + Fields!val3.Value <> 0, False, True)
This breaks RowNum, but we can amend the expression to ignore the hidden rows. We do this by NULLing them out (i.e. for SSRS set as Nothing) - CountDistinct will not consider any Nothing values:
=RunningValue(IIf(Fields!val2.Value + Fields!val3.Value <> 0, Fields!val1.Value, Nothing)
, CountDistinct
, "Tablix1")
Now RowNum is ignoring the hidden rows as required:
Related
new to SSRS
I have table with column 1 is Department, and column 2 is The calculation
For example sum of the cost...
I have used the expression below to sum the cost
but I want to exclude the department that are null, but its no joy..
=Sum(IIF(Fields!ReturnOrder.Value = "1" + IsNothing(Fields!Department.Value) = 1, Fields!Cost.Value, 0))
column 1 is still showing the null department. I do not wish to show this...
I just want to have a column 1 showing the department names, that does not show the null rows.. and column 2 sum of cost where return value = 1
please help
To make your expression work the way you have it, you need to change the plus to an AND for logical operations and leave the ISNOTHING as a Boolean (without the = 1):
=Sum(IIF(Fields!ReturnOrder.Value = "1" AND NOT(IsNothing(Fields!Department.Value)), Fields!Cost.Value, 0))
I'm not sure what the ReturnOrder is for but left your condition in.
The expression you are looking for is
=Sum(IIF(Fields!ReturnOrder.Value = "1" AND IsNothing(Fields!Department.Value) = False, Fields!Cost.Value, 0))
Tip: In case your value is decimal instead of 0 use Cdec(0) to avoid errors.
To avoid displaying null departments I would suggest filtering your SQL query.
You can also do it by filtering the tablix
Expression: IsNothing(Fields!Department.Value)
Type: Boolean
Operator: Equal =
Value: False
Doing so will hide Null departments and your expression can be simplified to
=Sum(IIF(Fields!ReturnOrder.Value = "1", Fields!cost.Value, 0))
The best way is to alter your query:
SELECT *
FROM [YourTable]
WHERE [Department] IS NOT NULL;
You can also select the details row, click the Properties tab, and enter a formula in the "Hidden" property
=IIF(IsNothing(Fields!Department.value), True, False)
This says, "if department is null, hide this row, otherwise show it". The first method is better because less data is returned to your report. The second method requires that all rows are returned, and the report has to sort through which ones to show.
Select the detail row (click the three lines), select the Properties tab, and replace "False" with that formula:
I have a dataset which brings in distinct values of a column 'A' of table 'B' and these form the select values for a parameter 'Param_A'. In addition to this I have a main dataset which brings in data from table 'B' and contains the column 'A' as 'Field_A'.I do not want to alter the main dataset and hence I am using a tablix filter to filter out the result set of the main dataset. The tablix filter is supposed to be performing the below functionality :
Expression:
Fields!Field_A.value in (Parameter!Param_A.value) or Fields!Field_A.value is NUll
Boolean Operator :
"="
Value:
True
But I am unable to use the operator 'in'. It gives me an error.Could you please help me out with this?
I used the 'inStr' Operator which eliminated the possibility of using 'in' operator:
iif(InStr(Join(Parameters!Project.Value,","),Fields!project_name.value)>0,
true,false)
This helped me!
I have a problem in SSRS 2008 described as below:
I have a matrix which is connected to a query, lets say Select * from Table. It is returning, lets say 50 rows of data. In my matrix, there is only one row. Lets say:
id name grade
[id] [name] sum[grade]
The matrix is grouped by 'id' and 'name' in Row Group. There is a row visibility expression for this row like =IIF(sum(Fields!grade.Value)>95,false,true). Assuming that for this situation, this table shows no data, all the returned 50 rows of data has a grade lower than 95 in total. Therefore, I see only the columns without any information on the screen like:
id name grade
What I want is to write "No Data" instead' like:
id name grade
No Data
Normally, when there is no data returning from the query, I would do it by going Tablix Properties and assign "No Data" to the NoRowsMessage property. This is not working for this situation, and I could not figure out how I can count the displayed row number in a matrix. Any help would be appreciated.
You can do this by adding a row add the end of the tablix and outside the Row Group.
Once the row is created type No Data in the first cell of the row.
Select the No Data row and go to Row Visibility property and set this expression:
=IIF(
Sum(IIF(Fields!Grade.Value>95,1,0))>0,True,False
)
When all rows have Grade 95 or less the No Data row will be shown but the data rows will be hidden.
UPDATE Update based on OP's feedback. Grade column is an sum expression.
In that case it is useful use the LookupSet function to get the grades by ID. They will be returned in an array data type so we require custom code to sum the ID grades.
Go to Report Menu / Report Properties..., select the Code tab and paste the following code.
Dim HiddenFlag as Integer = 0
Function CalculateHiddenFlag(ByVal items As Object()) As Integer
If items Is Nothing Then
Return HiddenFlag
End If
Dim sumItems As Decimal = New Decimal()
sumItems = 0
For Each item As Object In items
sumItems += Convert.ToDecimal(item)
Next
If (sumItems > 95 and HiddenFlag=0) Then
HiddenFlag = 1
End If
Return 0
End Function
Function GetHiddenFlag() As Integer
Return HiddenFlag
End Function
Now modify the [Sum(Grade)] cell expression an use this one:
=Sum(Fields!Grade.Value)+
Code.CalculateHiddenFlag(
LookupSet(Fields!ID.Value,Fields!ID.Value,Fields!Grade.Value,"DataSet15"))
Replace DataSetName by the actual name of yours.
Your matrix should look like this:
For the No Data row visibility property use the following expression:
=IIF(Code.GetHiddenFlag()=1,True,False)
It will return this when at least one row has Grade > 95.
And this when there is no rows which Grade is greater than 95.
Let me know if this helps.
I have a dataset called 'dsAllStuTargetData' - i'm trying to count the number of the 'A' values that appear in the column 'Target'.
I'm doing this using a textbox with an expression, I can count the total number of values using the following:
=Count(Fields!Target.Value, "dsAllStuTargetData")
However when I try to count where the value equals 'A' it doesn't work.
=Count(IIF(Fields!Target.Value, "dsAllStuTargetData")="A",1,0)
For this case you need a Sum, not a Count, i.e. something like:
=Sum(IIf(Fields!Target.Value = "A", 1, 0), "dsAllStuTargetData")
Count will just count the number of rows; the IIf doesn't do anything there - something like CountDistinct can be affected in certain cases but this will not work here.
However, Sum will take the total of all rows which meet the IIf condition, i.e. the total of all 1 values in the DataSet, which is what you're after.
IIF wants it's arguments in the format:
IIF(condition, true part, false part)
Which would equate to something like
Count(IIF(Fields!Target.Value = "A",1,0),"dsAllStuTargetData")
Does that work?
Ive just seen the following syntax : select * from table order by column = "b" desc
I guess that the rows with value "b" will come first but i am not sure.
What does the query mean and how sorting works in this case.
Ive searched on google about it but ... no success.
In SQL, you are not limited by sorting on values of existing columns: you can specify complex expressions inside your order by clause. This query sorts by the value of a boolean expression: the expression will be true for the rows where column = 'b', and false in all other rows. As the result, rows with column = 'b' will come first, because the order by clause specifies descending order, and in SQL, true is represented as 1, and false is 0.