How can i get RowNumber Matrix in SSRS Report - reporting-services

i am creating a matrix report.
need to show row number in the Matrix table under column and row grouping,
like this
A B C
X 1 1 1
Y 2 2 2
Z 3 3 3
Presently i am using this Expression for Row number but i am getting incorrect count.
=RunningValue(CountDistinct("YourTableName"),Count,"YourTableName")

Riddle-Master has a decent answer if your matrix is 100% full, ie there are no empty cells.
RowNumber("DataSet1") will contain the running sum of all fields
RowNumber("RowGroup") will contain the number of fields in each row group
However, if you have empty cells, you'll end up with some fractions and staggered numbers.
I found what I believe to be a better answer on this site, as long as you have a value in each row that is unique from the last. In my case, I'm using Customer_Num.
Go to Report Properties, open the Code property and paste the following code:
public dim LastNum as String
public dim rowCount as int32 = 0
Public Function GetRowNum(byval Num as String) as Integer
if Num <> LastNum then
rowCount = rowCount + 1
LastNum = Num
End If
Return rowCount
End Function
Then in the cell where you want the Row Number, past the following expression:
=Code.GetRowNum(Fields!Customer_Num.Value)
This should compare each value against the previous for each row, and give you an incrementing row number, no matter how many cell values are in each row.

From my experience RowNumber alone would give the sum all the dynamic fields from every row.
But a RowNumber with a scope on one field only would give the sum of the dynamic fields on one row alone.
Thus what solved it for me was:
=RowNumber("DataSet1")/RowNumber("StudentId")
When DataSet1 is from where I take all my matrix info and StudentId is only one of the fields in a row.

What worked for me for a matrix with both row and column grouping is:
=RowNumber("YourColumnGroupName") / CountRows()

Related

Using like operator in SSRS Expression

I have a tablix with following results.
SSRS Result
Since i am learning SSRS. i wonder how to Sum line total with respect to product name. Since product name has duplicate values but it has only M and Xl difference. If i use row group it won't total like i expected since it has M and Xl difference. I wonder how to write an expression for the total.
The desired result set
May 31 2011 S043659 Long-Sleeve Logo jerse M 3 $86.52
Long-Sleeve Logo jersey XL 1 $28.84
Total $115.36
mountain bike socks M 6 $34.20
i used this expression but giving me an error.
`IIF((Fields!Product.value = Previous(Fields!Product.value),Sum(Fields!linetotal.value))`
There's actually a few things wrong with your expression.
The IIF doesn't have a 3rd argument for the ELSE value. In this case, you'd want to use 0. So the expression would be IIF the fields match then LineTotal Else 0.
You want to have the SUM on the outside of the IIF, otherwise it will only SUM one row.
The matching without the size is trickier. I have it trim off the last 4 characters to exclude the size for a match - it may not work depending on your other Product names.
=SUM(IIF(LEFT(Fields!Product.value, LEN(Fields!Product.value) - 4) = LEFT(Previous(Fields!Product.value), LEN(Fields!Product.value) - 4), Fields!linetotal.value, 0))
The expression reads the SUM of (IF the Product matches the Previous Product then the Line Total else 0).
All this being said, it would actually be easy to crate a parent group and GROUP BY on the parent product. Unfortunately, your data uses a comma to separate one type (jersey) by size but a space in another (socks) so I don't see how to do it. If they all had a comma, I would create a Calculated Field on the dataset to use the product-line up to the comma.
=LEFT(Fields!Product.value, INSTR(Fields!Product.value, ",") - 1)
IF your Product line is either a comma or space to separate, you might be able to use this for your Calculated Field:
=LEFT(Fields!Product.value,
IIF(INSTR(Fields!Product.value, ",") > 0,
INSTR(Fields!Product.value, ",") - 1,
InStrRev(Fields!Product.value, " ") - 1) )

Replace custom function in Google Sheets with standard functions

I have a range of cells, and I want to accrue the number of times a column has the max value for its given row.
Sample:
headers -> a b c d e f g h
0 0 12 18* 1 0 0 0
30* 0 15 25 0 0 0 0
35 0 19 31 0 0 31 50*
40 10 19 31 0 2 5 55*
expected:
#max val per row-> 1 0 0 1 0 0 0 2
The maximum values are marked with an asterisk. The column a scores 1 because it has the maximum value in the second data row, the column d scores 1 as well because it has the maximum value in the first data row and the column h scores 2 because it has the maximum value in the third and fourth data rows. The rest of columns don't have the maximum value in any row, so they get a 0.
For just one row, I can copy this formula for for each column and it would do it, but I need something that applies the max row-wise COUNTIF(B2:B10, MAX($B2:$B10)).
I have written this google apps script, but I don't like its responsiveness (seeing the "Loading..." in the cell for almost a second is kind of exasperating compared with the snappiness you get with native functions):
function countMaxInRange(input) {
return [input.map(function(row) {
var m = Math.max.apply(null, row);
return row.map(function(x){return x === m && 1 || 0});
}).reduce(function(a, b){
var s = Array(a.length);
for (var i = 0; i < a.length; i++) {
s[i] = (a[i] + b[i]) || 0;
}
return s;
})];
}
Any ideas on how I could replace that code with built in functions? I don't care adding auxiliar rows or columns, as long as it is a constant number of them (that is, if I extend my dataset I don't want to manually add more helper rows or columns for each new data row or column).
I think I could add an extra column that collects the header of the column with the max value for each row; and then for each data column count how many times their header appears in that auxiliar column, but does not seem very clean.
FORMULA
=ArrayFormula(TRANSPOSE(
MMULT(
N(TRANSPOSE(NamedRange1)
=
INDEX(
QUERY(TRANSPOSE(NamedRange1),
"SELECT "&JOIN(",",("MAX(Col"&TRANSPOSE(ROW(NamedRange1))-INDEX(ROW(NamedRange1),1)+1)&")"
)),
2)
),
SIGN(ROW(NamedRange1))
)
))
where NamedRange1 is named range referred to the range.
Conditional formatting:
Apply to range: A1:H4
Custom formula: =A1=MAX($A1:$H1)
Explanation
Summary
The above formula no requires extra columns, just to set the range as a named range. In the formula NamedRange1 was used but it could be customized according to your preferences.
The result is a 1 x n array where n is the number of columns of NamedRange1. Each column will have the count of occurrences of maximum values by row on the correspondent column.
Featured "hacks"
ARRAYFORMULA returns an array of values.
Ranges greater than 1 x 1 are handled as arrays.
Using an array as argument with some functions and operators works in a similar way than a loop. In this case, this features is used to create a SQL statement to get the maximum value of each column of the input data. Note that the input data for QUERY is the transpose of NamedRange1.
N coerce TRUE/FALSE values to 1/0 respectively.
MMULT is used to make sums by rows
Note: the +0 shown on the image was inserted to force Google Sheets to keep the breaklines introduced on an edit of the formula without breaklines because if there are not significant changes to the formula, the breaklines are automatically removed due to the formula/result caching feature of Google Sheets.
Reference
MMULT Usage by Adam Lusk.

SSRS - Group set of rows based on calculated value from the row's data

I want to group ( display ) a set of row(s) based on a calculation on one of row's column data.
Lets say I have 3 columns in my tablix.
1. Description
2. Amount
3. Debit/Credit
based on the D/C value I would like to sum up the amount ( for debit its -ve and credit is +ve) until the total gets to zero and then group those rows into a different color or a line space between other set of rows.
Example output:
Description Amount D/C
xyz 10 D
sss 10 C
abc 15 D
vvv 5 C
ccc 5 C
abc 5 C
Thanks
Karthik
I've recreated your scenario using the dataset you have provided in the question.
I am using the Amount cell background-color property to group the sums.
This is the tablix I've created. The selected Cell background-property is set to a expression (see below):
In Report menu, Report Properties... / Code tab put this function in the text area.
Dim prevColor As String = "Red"
Dim accumulator As Double = 0
Public Function GetSumColor(ByVal value as Double) as String
Dim color As String
accumulator = accumulator + value
color = prevColor
If accumulator = 0 Then
If prevColor = "Red" Then
prevColor = "Yellow"
Else
prevColor = "Red"
End If
End If
Return color
End Function
This function will change the cell background color between Red or Yellow based on sums equals to zero (you can use the whatever color you want).
In the Amount cell background-color property use this expression:
=Code.GetSumColor(
IIF(Fields!D_C.Value="C",-Fields!Amount.Value,Fields!Amount.Value)
)
It will produce the following result:
Let me know if this helps you.

SQL updating data with duplicate information

So i've been working on this query for awhile and for some reason whenever i run it, it tries to update certain fields that are already equal in both tables. For example take these two tables:
AlldataTable
first__last__age__number
K____ D __ 17____ 7
K____ D __ 15____ 7
X____ X___ 12 ____21
NewDataTable
first__last__age__number
K____ D __ 17____ 7
K____ D __ 15____ 7
X____ X___ 13 ____22
so the goal here is to have the age field for x x update to 13 and the number field to update to 22 when the query is executed. But when i execute the code it would say for example that it is going to update all three entries when just the third should be.
UPDATE AllDataTable
LEFT JOIN NewDataTable ON (AllDataTable.first = NewDataTable.first)
AND (AllDataTable.last = NewDataTable.last)
SET AllDataTable.age = NewDataTable.age
,AllDataTable.number = NewDataTable.number
WHERE (
AllDataTable.age <> NewDataTable.age
OR AllDataTable.number <> NewDataTable.number
)
AND AllDataTable.first = NewDataTable.first
AND AllDataTable.last = NewDataTable.last;
It's because of your duplicated values in first and last. The database is seeing three hits on the WHERE clause:
Alldata first row against NewData second row.
Alldata second row against NewData first row.
Alldata third row against NewData third row.
This gives the appearance of only one row changing, but you get an affected row count of three because the first and second rows actually swap all their contents in addition to the third row being updated.

Report and Graphic in access 2007 - calculating values on queries

Picture a table with fields (Id, Valid, Value)
Valid = boolean
Value = number from 0 to 100
What I want is a report that counts the number of records where (valid = 0), and then gives me the total number of cases where (value < 70) and the number of cases where (value >= 70).
The problem is that the "value" field could be empty on some of the records and I only want the records where the value field is not empty.
I know that the second value (value>=70) is going to be calculated, but the problem is that I can't simply do (total number of records - number of records where value < 70), because there's the problem with the records where "value" is null...
And then I want to create graphic with these values, to see the percentage of records below and above 70.
"The problem is that the "value" field could be empty on some of the records and I only want the records where the value field is not empty."
Use a WHERE clause to exclude rows whose "value" field is Null.
Here is sample data for tblMetraton.
Id Valid Valu
1 -1 2
2 0 4
3 -1 6
4 0
5 0 90
I used Valu for the field name because Value is a reserved word.
You can use the Count() function in a query and take advantage of the fact it only counts non-Null values. So use Count() with an IIf() expression which returns a non-Null value (I used 1) for the condition you want to match and Null otherwise.
SELECT
Count(IIf(Valid=0,1,Null)) AS valid_false,
Count(IIf(Valu<70,1,Null)) AS below_70,
Count(IIf([Valu]>=70,1,Null)) AS at_least70
FROM tblMetraton AS m
WHERE (((m.[Valu]) Is Not Null));
Based on my sample data in tblMetraton, that query gives me this result set.
valid_false below_70 at_least70
2 3 1
If my sample data does not address the variability you're dealing with, and/or if my query results don't match your requirements, please show us you own sample data and the results you want based on that sample.