ssrs expression sum doesn't sum all column - reporting-services

I have a column like:
LEFT_PIN_HEIGHT_MIN
0
0
0
1
1
0
I wrote it to Tablix as below,
=Sum(Fields!LEFT_PIN_HEIGHT_MIN.Value)
I want to sum the fields and result must be "2" but it doesn't sum the column
and writes all the rows to Tablix.

I agree with the previous answer that your first choice ought to be to calculate this in the SQL, but sometimes that is not as practical.
Are you trying to display the column's sum in each row? If so, add the dataset name as a second parameter in the sum function, as in
=Sum(Fields!LEFT_PIN_HEIGHT_MIN.Value,"Dataset1")
Replace "Dataset1" with the name of your dataset. The Sum function you're currently using is defining the sum within the context of each row in your tablix. Adding the second parameter changes that context to return the sum for the entire dataset in each row.
If your tablix is large, this may result in a performance hit, since the expression will evaluate each time it is displayed, hence the preference toward doing it in your dataset query.

I suggest to do It with SQL. Use query to SELECT SUM(LEFT_PIN_HEIGHT_MIN)...
If you want to achieve It by SSRS expression you can do It in following:
Right Click on table1_Details_Group > Group Properties...
In Group on: field provide LEFT_PIN_HEIGHT_MIN click OK
To hide 0 > Right Click on left side of values row > Row Visibility check Show or hide based on an expression then write following expression: =IIF(Fields!LEFT_PIN_HEIGHT_MIN.Value = 0, true, false) click OK
It should work.

Related

Expression to calculate % in a report

I am building a report(report server project) using the Data Tools. I have a column Quantity it has a Total.
I need another column that calculate the share(%) of each line in the Quantity comparing to the Total.
The expression would be: Line_1_Share = Quantity_of_line_1/Total.
I tried =[Sum(Total/Quantity)] but it does not even accept as a valid expression.
If you right-click the textboxes that contain your working 'Quantity' and 'Total' values and look at the expressions you will see the correct format.
For exmaple your 'Quantity' expression might be something like
=Fields!Quantity.Value
or if it is in a grouped row it might be
=SUM(Fields!Quantity.Value)
your 'Total' expression might also be
=SUM(Fields!Quantity.Value)
When you use SUM() (or any similar aggregate) then the scope of the expression decides what is included in the sum. The scope can be a single row, a row group or an entire dataset. If you do not specify a scope then the position of the textbox determines the scope.
So, if you have a simple table with no grouping other than the total line and your dataset name is dataset1 then your expression would need to be
=Fields!Quantity.Value / SUM(Fields!Quantity.Value, "dataset1")
The above reads .... "For the current row, take the Quantity and divide is but the sum of all Quantities that are within the entire dataset called dataset1"
If this does not help, post your current report design including and row and/or column groups.

Dont's show rows in SSRS

I'm trying to achieve my report displaying a "No Data Available" message if no results are returned in my query.
I am trying to achieve this via an expression against the Row Visibility.
So I have a Tablix that looks like this -
If there is data available then I want the third, fourth and fifth line to show.
If no data exists then I want the first two rows to display.....
In the Row Visibility for the first two rows I have the following -
=iif(CountRows("RentTransactions") = 0, true, false)
In the Row Visibility for the remaining three rows I have the following -
=iif(CountRows("RentTransactions") > 0, true, false)
I have a filter on the Tablix that just limits it to "AccountType" = Water.
When I run the report between 01/06/2016 and 30/06/2016 - I know there are not transaction - so would expect my report to return the first two rows....
It doesn't it returns the bottom ones , with no data in it??
What am I doing wrong?
The DataSet is definitely called RentTransactions
There are a few issues going on here.
CountRows with the dataset name will always return the total number of rows in the entire dataset.
Row Visibility will make the entire row blank, but it will still take up space. This would look bad if there are alternating blank rows.
What you're really trying to do is control what is displayed in each cell. So in each cell you'll want to have an expression that checks whether or not to display a value. For example, for the Description field it would look something like this:
=IIf(Count(Fields!Transaction_Type.Value) > 0, Fields!Description.Value, "")
This expression will work by returning a count of 0 for NULL Transaction Types. You can customize this if needed.
Also make sure that the query is returning rows for dates with no transactions. Otherwise there's no raw data for the report to do anything with in the first place.

Applying different Visibility to each Tablix

I have a report showing hours and dollars that are written off. Jobs for this report are classified as NRB (non-billable) and non-NRB (billable). Each job type has its own Tablix in the report and I want to populate each Tablix based on a bit value - IsNRB.
All of the "0" IsNRB rows should populate the top Tablix and the "1" values should populate the bottom Tablix . For the most part this is working. What is happening, however, is that some Programs or Clients will have both NRB and non-NRB jobs, and it appears that as each Tablix works its way through the rows of the report dataset, it will capture and retain the first value for IsNRB and apply that to the entire report.
I have tried logic similar to the following in a number of places/ways:
=IIF(Fields!IsNRB.Value = False, Fields!CustProgram.Value, NOTHING)
The Grouping hierarchy of the report looks like this:
ProgramGroup
ClientGroup
Job/SubJobGroup
Detail is here
I have tried setting evaluative expressions similar to the one above on TablixVisibility, GroupVisibility, RowVisibility, and in the field expression itself. The behavior seems consistent in that the first row for that Program, Client, or Job sets the value of IsNRB for the entire report.
As a concrete example, the first Program, "Cascadia" has three rows where IsNRB = 1/True and two where IsNRB = 0/False, and the latter two rows of data are always misapplied because the value of 1/True is overriding the 0/False valued rows.
What is the proper approach to take that will allow the first Tablix to accept and display rows of data where IsNRB = 0 and the second Tablix to show those with a value of 1? Do I need to abandon the IsNRB bit datatype and just have a distinct dataset for each Tablix? That seems like a klunky way to approach the report.
Filter each table on the IsNRB field. Right click the tablix and select Tablix Properties. Select filter, then then select the field you want to filter against (IsNRB) and the value your want it to be (1).
This will put all records with a 1 for the field in one table, and with a 0 in the other

SSRS fills in arbitrary value when no result is returned in query

I have a report with column and row groups to calculate inventory.
there are some items in a column group that do not have any results in the query.
for example, item 009000 does not have any inventory entries in FY2016, I checked the query and indeed, there is nothing in it for that item in FY2016.
the report fills something in however and fills in the same value for every empty result. Even more confusing, this arbitrary value changes if I refresh the report. I want this field empty, I've used IsNothing and <> '' and <> 0 but to no avail, it always fills something in (second screenshot). I'm so confused. I have no idea what could be causing it, there is no calculation in the field. (first screenshot)
Change expression for example, if you have numeric field then use expression =Sum(Inventory.value) instead of =Inventory.value
s

Hide Column if all Rows are empty

I have a a Tablix in SSRS 2008 and I have a Column that sometimes has data and sometimes doesn't. I want to hide the column if NO rows have data.
So this would hide Column 2:
Column 1 Column 2 Column 3 Column 4
1 3 4
2 3 4
This would NOT hide Column 2:
Column 1 Column 2 Column 3 Column 4
1 3 4
2 2 3 4
Is there a way to do this in SSRS 2008?
Thanks!
Very old post, but I figured out a better solution for this when using an SSAS cube. Since all of the aggregation has already occurred within SSAS, you can simply check if the parent level of the hierarchy has a value.
This is done accordingly:
=IsNothing(Fields!Field.Value)
No summation or if statements necessary with SSRS. Because the function evaluates to true or false, and because the expression is evaluating whether or not to hide the column (i.e. True hides it) that is all you need in the formula.
If you have fields that contain values and not numbers then the following should work to hide columns that have only NULL values for each row in the column.
Place this code as an expression in the Column Visbility object for each column that you want to evaluate
=IIF(Count(Fields!<NAMEofCOLUMN>.Value) = Cint(0), True, False)
In design,
Go to the column, right click and select 'Column Visibility`
Select show or hide based on expression and give the expression as:
=iif(Fields!column_name.Value=Nothing,True,False)
I suspect you'll have to get inventive. For example run a query to get a count of non empty rows for the column. Then use the count result as part of an expression on the visibility property of the column. I.e. If count greater than zero... show.
This might help
Reporting Services - hide table column based upon report parameter
Select all Columns in the Tablix and set Visibility - Hidden properties as:
=IIF(Fields!ColumnSample.Value = Nothing, True, False)
You can explore column visibilty property of a tablix based on expression:
If its nothing then evaluate the condition to just Nothing.
Follow the link:
SSRS 2008 Column Visibility Expression Evaluates to true, column not visible