Reporting Services group with a condition - reporting-services

I have this source data :
First I want to group by "Name" (I already did this part), after this I want to create the"category" column, if a "Name" group have any row type1 = A, then the Category is "X" else category = "Z"
This is the result I want:
How can I get the category group-column in reporting services?

My defacto method for this would be to edit the SQL query feeding the report and add the logic to add the group there. I assume that's not possible or you don't have access to the SQL layer, so here a way to do it completely in SSRS:
Insert another column to the right within your Name group
For the field expression, do a lookupset on the name field value and check if A exists in the results
=IIF(Array.IndexOf(Lookupset(Fields!Name.Value, Fields!Name.Value, Fields!Type1.Value, "DatasetName"), A) > -1, "X", "Z")
If you build the expression piece-meal, use the following expression to first check that your lookupset is working:
=JOIN(LookupSet(...), ",")
Then add the IIF(Array.IndexOf(...,A) > -1, X, Z) to see if the returned array contains your "A" value.

Related

The Value expression for the textrun ‘Textbox15.Paragraphs[0].TextRuns[0]’ contains an error: [BC30201] Expression expected

I received this error when I am trying to run a select statement in a text box in SSRS. So, basically, I am trying to return a field which is not in the given dataset. So I have run a subquery which returns the value using the existing dataset as a container.
But I don't know how to represent that return value in the Expression field. Because the expression field returns a value which is within the dataset provided.
I have provided the SQL that I have written.
Any suggestions would be much appreciated.
My intention is to return the "CommentText" value. However, the dataset does not contain any commenttext field, but an EmpID field. So I have created the subquery below that brings up the CommentText from LaborDtlComment table and when it matches with the EmpID in the report dataset it returns the CommentText Value.
select [CommentReturnQuery].[LaborDtlComment_CommentText] as [LaborDtlComment_CommentText],
[EmpBasic].[EmpID] as [EmpBasic_EmpID]
from Erp.EmpBasic as EmpBasic
inner join (select [LaborDtlComment].[CommentText] as [LaborDtlComment_CommentText],
[LaborDtl].[EmployeeNum] as [LaborDtl_EmployeeNum]
from Erp.LaborDtlComment as LaborDtlComment
inner join Erp.LaborDtl as LaborDtl on LaborDtlComment.Company = LaborDtl.Company
and LaborDtlComment.LaborHedSeq = LaborDtl.LaborHedSeq
and LaborDtlComment.LaborDtlSeq = LaborDtl.LaborDtlSeq) as CommentReturnQuery
on EmpBasic.EmpID = CommentReturnQuery.LaborDtl_EmployeeNum
My aim is to show the CommentText value in a text field. So I will create the
text field and it will contain the SQL that I have written. Can anyone help
me in this case?
It maybe simpler to use the SSRS function lookup (single paired 1 to 1) or lookupset (multiple 1 to many).microsoft lookup reference
You will have to create the query/dataset to return CommentText from LaborDtlComment table with the EmpID

exclude nulls in column SSRS

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:

SSIS Derived Column condition to replace null values based on a specific date

I am working on a SSIS Package that will populate a SharePoint 2013 list with data from other SP lists.
I have created a Derived Column in the package, which is intended to replace null based on dates that are greater than or equal to a specific date in the data list. However, I am having trouble with the expression. Below is a condition and expression example that I am have trouble with.
REPLACENULL(ColumnName,"mm/dd/yyyy" > = GETDATE())
Any assistance to point out what I am doing wrong is appreciated.
Use this expression:
((DT_DATE)"9-1-2016") >= (DT_DATE)ColumnName ? NULL((DT_WSTR, 50)) : ColumnName
Notice: REPLACENULL is not useful for you here. What REPLACENULL does is that it:
Returns the value of second expression parameter if the value of first expression parameter is NULL". (See here)
You don't want to replace NULL, you want NULL!
Syntax for REPLACENULL is REPLACENULL(expression 1,expression 2) where
expression 1 :
The result of this expression is checked against NULL.
expression 2 :
The result of this expression is returned if the first expression evaluates to NULL.
If you're trying to REPLACE NULL values of a column based on another column's datetime condition, try something like this :
[column_1] >= GETDATE() ? REPLACENULL([column_2],"desired value") : [column_2]

Check if a field exists in parameters select value

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!

SSRS Parameter values in WHERE clause

(edited to clean up)
I have an SSRS report with a multi-value parameter. What I need is for each value of the parameter to correspond to a condition in the "where" clause.
So my query is like this:
select stuff,...
WHERE
column A != column B OR
column C != column D OR...
just like that all the way down. It's to give results only if there's a difference between different pairs of columns.
So hope I'm describing it well. So, for example, if the above is my where clause, I want the parameter to have values like this:
"Difference between A & B"
"Difference between C & D"
and be able to select multiple...so only the ones the user selects are incorporated.
EDIT - PARTIAL SOLUTION **********************************************
Ok I have the logic, thanks to the right direction from Hannover Fist, I came up with this:
WHERE
col 1 <> CASE WHEN CHARINDEX("Where1",#Parameter) = 0 THEN col 1 ELSE col 2 END OR
col 3 <> CASE WHEN CHARINDEX("Where2",#Parameter) = 0 THEN col 3 ELSE col 4 END
...etc.....
This way, if the parameter is not selected, that part of the where clause looks for results where that column is not equal to itself--so none, of course...
However, one problem remains. This works in SSRS if I only choose 1 of the parameter values, but if I choose more than one, I get an error "charindex function requires 2 to 3 arguments." >-(
I deployed it and it spat something slightly different:
Argument data type nvarchar is invalid for argument 3 of charindex function
Something about SSRS's handling of this is flapdoodle, but I'm not sure what.
I'm a little fuzzy as to how you're trying to do this.
How about having your WHERE clause in your SQL and use your parameter to determine whether that part of the WHERE is used? This may not be exactly what you need but should give you an idea of what I mean.
WHERE (ColA <> ColB or CHARINDEX("Where1", #Parameter) = 0)
Your Parameter would have Where1 as one of the selections (for the Value - the Label could be more descriptive). If it's chosen, the CHARINDEX result would not be 0 and the ColA <> ColB condition would need to be true to show that record.
Repeat for each parameter/WHERE combo you need.
Got it.
As edited above, this code works (helpful nudge in this direction from Hannover Fist):
WHERE
col 1 <> CASE WHEN CHARINDEX("Where1",#Parameter) = 0 THEN col 1 ELSE col 2 END OR
col 3 <> CASE WHEN CHARINDEX("Where2",#Paremeter) = 0 THEN col 3 ELSE col 4 END
etc...
And the parameter issue is new to my experience, but put simply (which is not done often--hence my difficulty :-P), SSRS includes the commas between parameter values (which makes sense since we can use an IN statement such as
WHERE column IN (#Parameter)
So that is why it complained when I selected more than one. Incorporating the excellent selected answer here:
Passing multiple values for a single parameter in Reporting Services
Solved the rest of the problem :)
When you are passing the multivalue parameter to dataset
join the multivalue parameter with expression
= JOIN(Parameters!multivalue parameter.Value,",")