lines break after X records in single ssrs page - reporting-services

I'm getting more than 200 records (for example, however, the number of records are dynamic) in a single table column in SSRS. I would like to do a line break after 25 records.
ReportTable result (Just an example):
Value
-----
jklsa
dfv
b
grt
trj
h
muik
rg
kuu
wd
gb
nm
wef
Final Rrport table desired output:
Values
-----------------
jklsa |muik | wef
dfv |rg |
b |kuu |
grt |wd |
trj |gb |
h |nm |
That is, after introducing line break, the records has to be moved to the "right side".
So, in this case instead of single column with 200 records, It should be 8 columns [column name can be same] each having 25 records.
This is what I have tried :
=IIF(CountRows(Fields!Request_Number.Value) > 25,vbCrLf,Fields!Request_Number.Value)
and
=IIF(CountRows(Fields!Request_Number.Value) > 25,Fields!Request_Number.Value, "") & vbCrLf
However, it throws error:
"The value of expression has a scope parameter that is not valid for
an aggregate function"
Hope I have explained this correctly.
What am I doing wrong? how to get the correct result?
Thanks

CountRows(Fields!Request_Number.Value)
wont give you correct count for your Rows on SSRS.
Instead use
RowNumber("DataSet1")
Note:"DataSet1" is your Dataset name.
By the way what exactly you wish to achieve. As you will be using Table or matrix do you wish to add pageBreak because linebreak works with Textbox and not with entire table.
Link for Ref:
https://learn.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/ms159225(v=sql.105)

Related

SumIIF Access Query

I am struggling to get the desired results i need using an Access query, and was wondering if what i was looking to do was actually achievable in one query, or whether i would need two queries and then export to Excel and interrogate the results there.
I've a table with a number of columns, i am specifically looking at three columns
Row Type - this will either be populated with A or U
Account Number - there will be potentially multiple instances of account number within the table. Although only once against row type "A", and multiple on row type "U"
Value - a currency field. At Account number level, the sum of "U" row, should equal the "A" value
I am looking to produce a query that will list three things.
[Account Number]
Sum of [Value] when [RowType] = "U"
[Value] when [RowType] = "A"
Would i need to create a new column in my table to generate a value for the requirement "Sum of Value when 'U')
I've tried
SUM(IIF([ROWTYPE]='U',[Value],0)) - but that doesn't seem to work.
I've also tried to use the builder within the Query to replicate the same, but again that also doesn't seem to work.
If all else fails i'm content to have to run two queries in Access and then join Excel, but i tihnk for my own learning and knowledge it would be good to know if what i am trying to do is possible.
I was hoping this is possible to compile in Access, but my knowledge of the application is seriously lacking, and despite looking on the MS Access support pages, and also some of the response on the StackOverflow forums, i still can't get my head around what i need to do.
Example of the data
Row Type
Account ID
Value
A
123456789
50.00
U
123456789
30.00
U
123456789
20.00
A
987654321
100.00
U
987654321
80.00
U
987654321
20.00
The data has been loaded into Access, table called "TEST"
This is the SQL i've got, but doesn't give me the desired results.
SELECT [TEST].[ROW TYPE], SUM([TEST].[VALUE]) AS [TEST].[ACCOUNT ID]
FROM [TEST]
GROUP BY [TEST].[ROW TYPE], [TEST].[ACCOUNTID]
When the query generates, would hope to see two rows, one for each account number.
Three row -
Account Number
Sum Value (where row is U)
Value (Where row is A)
I currently get 4 rows in the query. Two results for each account number, one result is the Value when Row Type = A, the other when Row Type = U.
I guess this is what you are after:
SELECT
[Account ID],
Sum(IIf([Row Type]="A",[Value],0)) AS A,
Sum(IIf([Row Type]="U",[Value],0)) AS U
FROM
TEST
GROUP BY
[Account ID];
Output:
Account ID
A
U
123456789
50,00
50,00
987654321
100,00
100,00

Get count of specific values in a single field for a given group of records

I have a set of records in SSRS (SQL Server 2019) with a "code" field that has a value from a list (M, S, W). I'm grouping on another field and need to get counts of this field's value within the group (i.e., how many rows in the group have S, how many M, etc.)
I'm probably describing this poorly but this is a simplified version of what I'm trying to do.
name | code
-----|-----
Bob | M
Bob | S
Bob | S
Bob | W
Joe | S
Joe | S
Grouping on name, I'd like to be able to see this:
Bob group M = 1, S = 2, W = 1
Joe group M = 0, S = 2, W = 0
I'm trying to write an expression to hide/show a group based on these values so I need to be able to test them. So far, I'm not able to figure out how to do this in SSRS. Can it be done?
FWIW, I've previously accomplished this in Crystal Reports by creating variables within the group and literally counting each value while printing the records and then examining them at the end of the group.
I would probably just sum 1 for each matching value. Assuming the expression sits within your rowgroup then you won't need the scope specified
=SUM(IIF(Fields!code.Value = "M", 1,0))
Obviously needs to be repeated for each code but that should work.
Another option is to simply use a Tablix report.
For example, set the 'Row Groups' to Name and 'Column Groups' to Color and use Count as the aggregate.

Query Data Type Mismatch in Criteria Expression Access

I am trying to filter out all Names that do not match in my data base using Same?:StrComp(Str1, Str2). When I run the the field in my Query My Columns have 0's for matching and 1,-1, even #ERROR because one side of the compare is empty.
Same? Our DataBase Name Other DataBase Name ID
0 Aaron B AARON B 00002
1 Aaron P. AARON J M P 00003
#Error Ainsley W #Error 00004
So I tried in the Criteria section in design view Not = 0 to get all entries that are not the same, but I get the error message Data Type Mismatch. I then triedIff(StrComp(Str1, Str2)=0,"Yes","No") then in the Criteria section "No" Same error came up.
Any thoughts?
So for some reason it works using Iff(StrComp(Str1, Str2)=0,"Yes","No")
then in the criteria Like "No*" then it filters all the No's also I had to filter out the #Error message in another query so those do not show up.

Resize tables based on number of records in SSRS

I have two table having data like below:
SELECT *
FROM [dbo].[TestTable_1]
ID Value
----------
1 gjha
2 dc
3 d
4 ds
5 dg
6 hn
2nd table:
SELECT *
FROM [dbo].[TestTable_2]
Value
-----
jklsa
dfv
b
grt
trj
h
muik
rg
kuu
wd
gb
nm
wef
I'm fetching the data in SSRS report as below:
Question is:
How can I maintain the table size same? That is, if small table in SSRS report has 6 records (which is in this case),
the bigger one should adjust same size as small and the extra (/more) records that are coming in the large table should shift to right.
Here is the expected output from SSRS
Value Value
-------- -----------------
gjha jklsa |muik | wef
dc dfv |rg |
d b |kuu |
ds grt |wd |
dg trj |gb |
hn h |nm |
Note: The above details are just example, however, the number of records are really dynamic.
This is not a full answer as it's just what came to mind and is completely untested.
First thing is to search SO for ways to create a multi-column table, there are plenty of answers already so I won't explain in detail here. They usually involve adding RowNumber to each row which you can then use to calculate a matrix row and matrix column number, the column number can be used in a matrix as the column group. (e.g. if the row limit is 6 and the row number is 14, that will have a final row number of 2 (14 mod 6 = 2) and a column number of 3 as Floor(14/6)+1 = 3.
Next, create dataset that just gets the highest row count from each of your tables. Something like
DECLARE #a int
DECLARE #b int
SELECT #a = COUNT(*) FROM myTableA
SELECT #b = COUNT(*) FROM myTableA
SELECT CASE WHEN #a<=#b THEN #a ELSE #b END AS maxRows
Now you have the size of the smallest table, you can pass that as a parameter to the proc that gets the actual data from the two tables (this would be 6 in our example above)
I just answered a similar question here: https://stackoverflow.com/a/56350614/2033717
You can adapt this solution to your situation by replacing the 3 in the expressions with:
=Floor(Count(Fields!ColumnName.Value, "Dataset1") / Count(Fields!ColumnName.Value, "Dataset1"))
In other words, you're determining how many columns you need. And then grouping each row of the dataset into rows and columns of the matrix. This will work if you know the second table can be bigger than the first, but I'm not sure if it will work both ways without some additional conditions on the expressions.

Simple IIF statement to determine a sum

I am a rookie to SSRS and am having difficulty obtaining a Sum.
I want the cell to Sum the distinct values of "UnitNumber" which is what the report is using to generate each row of my table. The reasoning behind this is that behind the complex report, Unit numbers are distinct and provide me with distinct SqFt Values. For example:
Unit # | Sqft|
Unit 001 | 472 |
Unit 002 | 600 |
Unit 004 | 1203|
The below does not work:
Sum(IIF(Fields!Unitnumber.Value,1,Fields!SqFt.Value)
I either get "Contains an error: cannot be converted to String" or, #Error in the cell. I cannot solely use Sum(SqFt) because it dumps an aggregate of the whole dataset query (every single row summed up) Any ideas?
It seems that your IIF missing main condition. It can be something like below or do as per your requirement.
Sum(IIF(Fields!Unitnumber.Value=1,1,Fields!SqFt.Value)
Also, I would suggest you to make your expression like below,
=SUM(IIF(Fields!Unitnumber.Value = 'putyourcondition', Fields!SqFt.Value, 0))