SSRS Alternating Row Colour Within Groups - sql

I have a ssrs table report with row grouping and I would like to know how to change the colours of rows in groups without changing the background colour of the group column itself. With the answers I have found and implemented I get the effect of the second table in the picture when I want the effect of the first table:
Any help will be much appreciated.
This is a picture of the actual report and it's grouping:

The RowNumber technique only works on the Details group i.e. the lowest level group (with no Group columns defined). Think of it as returning the Row in the Dataset.
Instead I would write an expression that calculates the equivalent to RowNumber, but for the Group level - typically something using RunningValue ... CountDistinct on the Group Key field, like this:
= Iif ( RunningValue ( Fields!tableid.Value , CountDistinct , "TheNameOfYourGroup") Mod 2 = 0, "White", "WhiteSmoke")

I need to apply the alternation to all rows including Total rows so:
'define Report Variables: ActiveRowColour, ColourA, ColourB
'Call this function in one cell per row by setting => BackgroundColor=Code.NewActiveRowColour(Variables!ActiveRowColour.Value)
'Then All other cells on that row set -> BackgroundColor=Variables!ActiveRowColour.Value
Public Function NewActiveRowColour(ByVal sActiveRowColour As String) As String
If sActiveRowColour = Report.Variables!ColourA.Value Then
Report.Variables!ActiveRowColour.Value = Report.Variables!ColourB.Value
Return Report.Variables!ColourB.Value
Else
Report.Variables!ActiveRowColour.Value = Report.Variables!ColourA.Value
Return Report.Variables!ColourA.Value
End If
End Function

Related

Serial Numbering an SSRS Table with Grouping And Headers

[Report Design]
Here is an Example for a report that I am working on.
It is grouped by "CostCenter" Field and above each group there is a header with the SUM of the "Betrag" Field.
I want to Number each Column in the Table with the Headers as well.
I tried using RowNumber(Nothing) or Row Number("DataSet") Or Running Value.
I get these results [Report View]
I think there should be a way or a Formula that connects both Fields in the Colmun Row Number or "Zeilennr" that results with a Correct Row Numbering for each Row
You can almost do this. The number would not work if placed to the left of the inner group, it needs to be at the same level as the details group but it will give you the correct number. I've only done very limited testing but it seems to work.
Go to the report's properties and then to the code tab.
Now add the following custom code function
Public rn as Integer
Public Function GetRn() AS Integer
rn = rn +1
return rn
End Function
Now in the text box where you want the number to appear use the expression
=Code.GetRn
All this does in increment the public variable by 1 then return it. It has no concept of the row it lies on, so if you did not include this on a group row, the numbers would remain sequential.
Here is a demo based on a small test report I had..
Design showing the position of the expression
Gives this result
Add the same expression to more text boxes...
Give these results...

SQL Query getting not results

I have a Select statement that gets the items based on the greatest date. it works but these are selected value from asp.net controls and one of the controls is a multiselect listbox
as you can see DynamicAtrributeID 937766 is show one time:
I need it to show all the rows that were in 937766 as well as the other rows which could be just one row. Is this possible
SELECT VotingValueDynamicId,
DecisionValueID,
DynamicAttributeID,
VotingValue,
DecisionSurveyID,
VALUEDATEUPDATED,
RECORDSTATUS,
FROM Adjudicate.ONCOLOGY_DynamicDecisionValuesForCaseManager AS a
WHERE (VALUEDATEUPDATED =
(SELECT MAX(VALUEDATEUPDATED) AS Expr1
FROM Adjudicate.ONCOLOGY_DynamicDecisionValuesForCaseManager AS b
WHERE (a.DecisionValueID = DecisionValueID) AND a.DynamicAttributeID = DynamicAttributeID) ) AND (RECORDSTATUS <> 'D')
In the example shown, all the rows with DynamicAtrributeID = 937766 have different values on VALUEDATEUPDATED, so the query is showing one row for that DynamicAtrributeID because that's what you're doing, filtering and getting only the row wich has the max VALUEDATEUPDATED.
In other words, you can't get more than one row for a DynamicAtrributeID if you're filtering by his max(VALUEDATEUPDATED).
As #necoflecap1 said , the issue is your filter condition, For VALUEDATEUPDATED , you are filtering max(VALUEDATEUPDATED) which any way going to give 1 value per DynamicAttributeID and DecisionValueID combination,since your filter in subquery is
WHERE (a.DecisionValueID = DecisionValueID) AND (a.DynamicAttributeID =
DynamicAttributeID)
I can see two possibilities here , either add one more filter for VotingValue column
WHERE (a.DecisionValueID = DecisionValueID) AND (a.DynamicAttributeID =
DynamicAttributeID) and (a.VotingValue=b.VotingValue)
or Do a
group By VotingValue
inside filter subquery for max(VALUEDATEUPDATED) so that aggregation will perform for every VotingValue (which is the column I can see coming with a different value for DynamicAtrributeID 937766)

Qlikview conditionally hide expression in pivot table

Struggling with a way to hide an expression on certain rows in my pivot table below. Basically, I want to be able to hide my expression 'Cumulative' when the FINANCIAL_PLAN_TYPE is not equal to 'OB_VARIANCE_TO_T1'. I figured out a way to change the text format on the lines with other FINANCIAL_PLAN_TYPE so that it appears hidden (what is showing in the picture below), but I'd really like the whole row to go away in these cases.
Additionally, I do not want to see a Total on the Cumulative lines if possible, but I do want to keep them on the Sum(AMOUNT) lines.
My expression for Cumulative is:
sum(aggr(Rangesum(above(sum({<YEAR={"$(vYear_Current)"},FINANCIAL_PLAN_TYPE={"OB_VARIANCE_TO_T1"}>}AMOUNT),0,MONTH_NUM)), FINANCIAL_PLAN_TYPE, MONTH_NUM))
I tried to use the function Only, as well as, I tried conditionally enabling/disabling the expression but I can't seem to get it to work. Any ideas would be great. Thanks!
FINAL SOLUTION:
1) Load Inline Table
Load * Inline
[MyDim
Cumulative
Vals
];
2) Created calculated dimension to combine the two desired dimensions into one and show blank ('') in cases that you don't want to show (this leaves one blank line on the pivot but there is probably a way to hide that too):
=If(MYDim='Cumulative' and FINANCIAL_PLAN_TYPE='OB_VARIANCE_TO_T1','Orig Budg Cumulative Variance',if(MYDim='Cumulative' and FINANCIAL_PLAN_TYPE='LE_VARIANCE_TO_T1','LE Cumulative Variance',if(MYDim <> 'Cumulative',FINANCIAL_PLAN_TYPE,'')))
3) Create a new expression that does one calculation in the case of your made up dimension = Value A and something else in case your calculated dimension = Value B
If(MYDim='Cumulative' and (FINANCIAL_PLAN_TYPE='OB_VARIANCE_TO_T1' OR FINANCIAL_PLAN_TYPE='LE_VARIANCE_TO_T1'),If(ColumnNo()=0,'',sum(aggr(Rangesum(above(sum({<YEAR={"$(vYear_Current)"}, DEPARTMENT={"20820"}, ACCT_TYPE={"Capital"}>}AMOUNT),0,MONTH_NUM)),
FINANCIAL_PLAN_TYPE, MONTH_NUM))),IF(MYDim='Vals', SUM({<ACCT_TYPE={"Capital"},DEPARTMENT={"20820"}>}AMOUNT)))
You cannot hide expression on some of the rows - not possible in Qlikview.
The workaround is to create a dummy floating table that holds the second column as a dimension and then use it in your chart instead of the two expressions. Then you will have one expression that says something like that :
If ( dummyField = 'Cummulative' and = 'OB_VARIANCE_TO_T1',
{Use your second expression here} ,
If (dummyField = 'sum(Amount)', {use your original first expression here}))
Regarding the Total, check out this link in the "Tricking the Pivot Table" section

Pivot Table Independent Grand Total Row

Is it possible to have a grand total row in a pivot table that is independent of selections? The table I am currently working with has region & branch dimensions and then several columns of data. I would like the company total to display at the bottom row regardless of what regions and/or branches are selected.
You can use Dimensionality() function.
As you can see from the picture below the rows have Dimensionality() = 2 and the total row have Dimensionality() = 0
So in your case the expression will be something like this:
if( Dimensionality() = 0,
sum( {< Region=, Branch= >} Value),
sum( Value )
)
(Don't forget to remove/disable the Dimensionality() column to test it. If not removed the chart will not behave as normal)
Using the above expression the total row will show the sum( Value ) ignoring the selections in Region and Branch fields:
Also you can see that Dimensionality() is changing depends on the table aggregation. For example when collapse the Region the Dimensionality() function is returning 1 for the rows:
No need to tell you that if you have decent amount of data such expressions will decrease the performance!
There is also and SecondaryDimensionality() function which is basically the same as Dimensionality() but for the horizontal pivot dimensions.
An easier way of accomplishing this would be to have a straight table directly below your pivot table using set analysis to exclude selections.

How to use multiple conditions (With AND) in IIF expressions in ssrs

I want to hide rows in SSRS report having Zero Quantity.
There are following multiple Quantity Columns like Opening Stock, Gross Dispatched,Transfer Out, Qty Sold, Stock Adjustment and Closing Stock etc.
I am doing this task by using following expression:
=IIF(Fields!OpeningStock.Value=0 AND Fields!GrossDispatched.Value=0 AND
Fields!TransferOutToMW.Value=0 AND Fields!TransferOutToDW.Value=0 AND
Fields!TransferOutToOW.Value=0 AND Fields!NetDispatched.Value=0 AND Fields!QtySold.Value=0
AND Fields!StockAdjustment.Value=0 AND Fields!ClosingStock.Value=0,True,False)
But by using this expression in row visibility, report hides all the rows except Totals Row. Even though report should show rows having Quantities of above mentioned columns.
Total values are shown correct.
Note: I set this row visibility expression on Detail Row.
Without using expression result is as following.
For the first 2 rows all the quantities are 0 (ZERO), i want to hide these 2 rows.
How can I fix this problem, or which expression must I use to get required results?
Could you try this out?
=IIF((Fields!OpeningStock.Value=0) AND (Fields!GrossDispatched.Value=0) AND
(Fields!TransferOutToMW.Value=0) AND (Fields!TransferOutToDW.Value=0) AND
(Fields!TransferOutToOW.Value=0) AND (Fields!NetDispatched.Value=0) AND (Fields!QtySold.Value=0)
AND (Fields!StockAdjustment.Value=0) AND (Fields!ClosingStock.Value=0),True,False)
Note: Setting Hidden to False will make the row visible
You don't need an IIF() at all here. The comparisons return true or false anyway.
Also, since this row visibility is on a group row, make sure you use the same aggregate function on the fields as you use in the fields in the row. So if your group row shows sums, then you'd put this in the Hidden property.
=Sum(Fields!OpeningStock.Value) = 0 And
Sum(Fields!GrossDispatched.Value) = 0 And
Sum(Fields!TransferOutToMW.Value) = 0 And
Sum(Fields!TransferOutToDW.Value) = 0 And
Sum(Fields!TransferOutToOW.Value) = 0 And
Sum(Fields!NetDispatched.Value) = 0 And
Sum(Fields!QtySold.Value) = 0 And
Sum(Fields!StockAdjustment.Value) = 0 And
Sum(Fields!ClosingStock.Value) = 0
But with the above version, if one record has value 1 and one has value -1 and all others are zero then sum is also zero and the row could be hidden. If that's not what you want you could write a more complex expression:
=Sum(
IIF(
Fields!OpeningStock.Value=0 AND
Fields!GrossDispatched.Value=0 AND
Fields!TransferOutToMW.Value=0 AND
Fields!TransferOutToDW.Value=0 AND
Fields!TransferOutToOW.Value=0 AND
Fields!NetDispatched.Value=0 AND
Fields!QtySold.Value=0 AND
Fields!StockAdjustment.Value=0 AND
Fields!ClosingStock.Value=0,
0,
1
)
) = 0
This is essentially a fancy way of counting the number of rows in which any field is not zero. If every field is zero for every row in the group then the expression returns true and the row is hidden.
Here is an example that should give you some idea..
=IIF(First(Fields!Gender.Value,"vw_BrgyClearanceNew")="Female" and
(First(Fields!CivilStatus.Value,"vw_BrgyClearanceNew")="Married"),false,true)
I think you have to identify the datasource name or the table name where your data is coming from.