SSRS Bad Results - reporting-services

I have a simple matrix that is returning the wrong results in rendering. I have tried rebuilding the project and deleting the rdl.data file for the report.
I am using a shared data source to set the parameters. I have verified the actual data returned is correct. I verified the datasource that sets the parameters is also returning the correct results
The code is basic
SELECT ACCOUNT_NUMBER
,COMPANY_CODE
,SUM(CONVERTED_AMOUNT) AS CONVERTED_AMOUNT
FROM aTable <br />
WHERE COMPANY_CODE IN ('ABC', 'EDF', 'JKL')
AND (ACCOUNT_NUMBER = '12020000') AND
(#PrePostCommit = 'Post' AND CAL_ACCTG_PERIOD <= #EndPeriod OR
#PrePostCommit = 'Pre' AND CAL_ACCTG_PERIOD <= #PreEndPeriod)
GROUP BY ACCOUNT_NUMBER, COMPANY_CODE
I tried rebuilding the matrix, and the results are still wrong. The full report has multiple tables from different data sets and data sources.
Any suggestions?
enter image description here

SSRS doesn't change your values so the issue is most likely either the query or the expressions in the report. I'm assuming your expressions are pretty straightforward like just checking a Sum.
Check this part of your WHERE clause:
(#PrePostCommit = 'Post' AND CAL_ACCTG_PERIOD <= #EndPeriod OR
#PrePostCommit = 'Pre' AND CAL_ACCTG_PERIOD <= #PreEndPeriod)
You are mixing AND and OR and are not going to get the intended behavior. You should use parentheses to specify the order of operations like so:
((#PrePostCommit = 'Post' AND CAL_ACCTG_PERIOD <= #EndPeriod) OR
(#PrePostCommit = 'Pre' AND CAL_ACCTG_PERIOD <= #PreEndPeriod))

Related

Is it possible to have a group by parameter in a SSRS Matrix report and have the columns rearranged depending on the group by chosen?

I haven't really worked with SSRS Matrix reports and I'm not sure if what I am trying to do is even possible.
The user can enter a begin and end year. They want the ability to group on either CBA, CRA or Client. The CBA and CRA choice would subtotal after each name, but the client would not. The columns to include would remain the same for each choice. However, they want whatever is grouped by to be moved to the front of the report. If you choose CBA, the columns relating to CBA should appear first. If you choose client, the columns relating to client should appear first.
Is any of this possible with a matrix report? If so, where do I start? Should any of this be done in the stored procedure or should it all be done in Visual Studio? I am using Visual Studio 2017. Below is a sample of what the output should look like.
Any help is greatly appreciated.
report sample
This is certainly possible. There are several ways to do this and you will have to choose how much of it is done in your dataset query/stored proc and how much is done via SSRS expressions.
There are a few things to think about no matter what route you decide on.
Your dataset query or stored proc must always return a dataset that has the same column names with the same datatypes and in the same order
Avoid hiding columns in the report designer as this does not work well
If the dataset returns lots of rows then you might want to do some of the work in the query
The SSRS Way:
If you wanted to do this entirely in the report designer, all the affected columns and groups would need to be set as expressions. For example, in a simplified version of your report, the second column expression would be something like.
=SWITCH(
Parameters!myParam.Value = "CBA", Fields!CBAName.Value,
Parameters!myParam.Value = "CRA", Fields!CRAName.Value,
Parameters!myParam.Value = "Client", Fields!ClientName.Value
)
The Columns header would also have to be a similar expression.
=SWITCH(
Parameters!myParam.Value = "CBA", "CBA Name",
Parameters!myParam.Value = "CRA", "CRA Name",
Parameters!myParam.Value = "Client", "Client Name"
)
The Row Group total (in grey on your example) would also have to be a similar expression.
You would have to repeat this for all affected columns.
Next
You would also need to change the RowGroups in a similar fashion. So you would add a row group and then the "Group On" and "Sort By" expressions to the same thing.
=SWITCH(
Parameters!myParam.Value = "CBA", Fields!CBAName.Value,
Parameters!myParam.Value = "CRA", Fields!CRAName.Value,
Parameters!myParam.Value = "Client", Fields!ClientName.Value
)
It's quite a long winded process but it's not actually that bad to do.
The SQL Method
The idea is basically the same, based on the parameter we pass in, we swap out the columns in the results but we alias them so they look the same in the SSRS dataset. We also have to provide the text for the column headers in the results so we don't have to work it out in the report designer.
Here's a very simple example.
SELECT
CASE #myParam
WHEN 'CBA' THEN CBAName
WHEN 'CRA' THEN CRAName
WHEN 'Client' THEN ClientName
END AS ColumnAValue
CASE #myParam
WHEN 'CBA' THEN 'CBA Name'
WHEN 'CRA' THEN 'CRA Name '
WHEN 'Client' THEN 'Client Name'
END AS ColumnACaption
, *
FROM myTable
Here we are swapping out the content of ColumnAValue and ColumnACaption. In the report designer, we would display ColumnAValue and set the Column Header expression to
=FIRST(Fields!ColumnAHeader.Value)
The Row Groups would both simply sort by ColumnAValue
This method means a lot less work in the report designer.
There are other options but these two methods I what I usually go for as they are the simplest. The SQL method is easier for other developers to understand because there is not much 'hidden' such at the row groups sorting and grouping properties.
At the end of the day it's down to you to decide what you feel comfortable with but hopefully this gives you enough to start.

SSRS custom code issue

I am working on a SSRS report which has a Table with 2 groups. Used custom code to store the outer group data and display it in the header. This works great for most of the data. However, found couple of instances where the last page of the group( A group can run into multiple pages and there is a page break at the start of each group) is displaying the data of the next group in the header. When I display the stored group data in the group footer, the group details are correct. Confused as to why the header is displaying incorrect data for a few groups. Any pointers as to why this is happening?
Custom code:
Public Shared Dim field as String
Public function Set field(ByVal Val as String)
field1 = Val
End Function
Expression in Outer group to save the group data:
=Code.Setfield(field name)
Expression to display the saved group data in Header:
=Code.field1
Thanks.
Resolved it by adding group variable and using PageName property.
Set the group variable as a concatenation of the group fields that I required. Set PageName to the group variable.
In the header use Globals!PageName to access the group data. Spilt the concatenated values using the split function.
Thanks!

How to implement Having Clause in SSRS

I'm New to SSRS.
Im trying to create a report where i need to group by [DATA Flag] column which is working fine ,but once the data is grouped i need to set the DATA FLAG ="TotalCancellations" and there is another column CancellDays which i need to set it as <120 .
I tried
Option 1:-
So to achieve this i have added TWO filters one with
Expression : DATA FLAG
Operator =
and Value as TotalCancellations
and the other filter as follows
Expression : Cancelldays
Operator =
and Value as < 120
But its not working and giving empty result,i have records with Cancelldays <120
Option 2 :-
Right click on Group and in General Tab ,Group on Expression as below ]
Fields!DFlag.Value = "TotalCancellations" AND Fields!DFlag.Value <120
which didnt work :(
this is similar to writing having clause in SQL i believe but im not getting how to implement that here in SSRS.
i can add in SQL Query but its already a huge query with lot of unions so please suggest me if there is any way i can implement here in SSRS
Im using Matrix in SSRS 2008
Adjusting the syntax for your option 1 is probably the easiest solution. In the Group Properties, under the Filters section, enter these two filters:
Expression: [DFlag] (Text)
Operator: =
Value = TotalCancellations
Expression: =Sum(Fields!CancelDays.Value) [enter this in the expression builder] (Integer)
Operator: <
Value: 120
Putting all the filters in a single expression, like your option 2, can be useful if you need to filter by one criteria OR another.
Below are the filer expressions
and this is how group by is
The filter should be implemented at the tablix level, not at the group level.

SSRS Expression in field using IN

I am trying to filter the data returned in a field using multi-value parameters. I need to filter based on 3 conditions:
--Before a Warranty End Date
--AND Service Type on the record must match one of the MULTI-VALUE parameters selected by the user
--AND Order Type on the record must match one of the MULTI-VALUE parameters selected by the user
Currently, this works for the first selection I described above (to sum only those records with a service date <= warranty end date , however, I cannot get the syntax to also check the 2 other fields based on the parameters selected...
Sum(iif(Fields!FirstServiceDate.Value <= Fields!WarrantyEndDate.Value, CDbl(Fields!ExtendedCost.Value), CDbl(0)))
Attached is my layout. Eventually I would like initially display everything to the left of % remaining and allow the user to drill down to see the invoice details
warranty
I don't know what is your reason to use parameter to filter the dataset instead of filter your query directly. However this could be what you are looking for.
Try this:
=Sum(iif(
Fields!FirstServiceDate.Value <= Fields!WarrantyEndDate.Value
AND
Join(Parameters!MultiValSTParam.Value,",").Contains(Fields!ServiceType.Value)
AND
Join(Parameters!MultiValOTParam.Value,",").Contains(Fields!OrderType.Value)
,CDbl(Fields!ExtendedCost.Value)
,CDbl(0)
))
EDIT: Edition based on OP comments.
You should use the parameter to filter the query that is generating your dataset at T-SQL level.
Create #WarrantyEDParam (date type), #ServiceType and #OderType parameters, then use them in your query something similar to this.
select
me.equipment_id,
me.WarrantyEndDate,
me.WarrantyReserveAmnt,
so.invoice_id,
so.service_type,
so.order_type,
so.cost,
so.price
from
master_equipment me
left join sales_order so on me.equipment_id = so.equipment_id
where me.WarrantyEndDate <= #WarrantyEDParam
or so.equipment_id is null --This line was added
and so.service_type in (#ServiceTypeParam)
and so.order_type in (#OrderTypeParam)
Now you will get data filtered directly from the query, so to get the sum of ExtendedCost use:
=Sum(CDbl(Fields!ExtendedCost.Value))

ORA 01797- operator must be followed by any or all

I am testing a condition like this in the where clause of a subquery. But I am getting the error "operator must be followed by any or all" when I execute the SSRS report.
dbase is oracle. And i need to use IN with parameter because the parameter in SSRS report is multivalued. I am using a separate function to generate dates that go in :P_Date.
I need to check if this date is = or < or null . All three conditions need to be tested.
where
trunc(tt.fyh_fecha) IN (:P_Date) OR
trunc(tt.fyh_fecha) <(:P_Date) OR
trunc(tt.fyh_fecha) IS NULL AND
tc.cod_tree = 'blue' AND
tt.color_flower = 'pink'
This doesnt seem directly possible - you are trying to use a parameter containing an array of values against the < operator which only expects one value. Your design doesnt make any logical sense to me either (<= multiple dates?), but anyway ...
I would add a join to a Calendar / Date Dimension table, where I would apply the IN (:P_Date) criteria to get a list of Date values as a deliberate cross join.
Then I would replace:
trunc(tt.fyh_fecha) IN (:P_Date) OR
trunc(tt.fyh_fecha) <(:P_Date) OR
with:
trunc(tt.fyh_fecha) <= Dim_Date.Date_Value