I have a list of data, with sequence id 1, 2, 3, ..., 9
I want to insert them into SSRS report in the form of 3x3 table, arranged by sequence id
1 2 3
4 5 6
7 8 9
I should use list, or table, or matrix? Any solution for this arrangement? Thanks
I would typically use a matrix for this. You can calculate the row and column numbers for each row of data in your table and then use that for your row and column groups in the matrix.
Here's an example...
Note: You might not have or want the 'label' field so just swap this out for whichever field you want to show when we get to the report design.
Here's some sample data with the Row and Col calculated
DECLARE #t TABLE (Seq int, Label varchar(10))
INSERT INTO #t VALUES
(1, 'AAAAA'), (5, 'BBBBB'), (10, 'CCCCC'),
(20, 'DDDDD'), (50, 'EEEEE'), (100, 'FFFFF'),
(101, 'GGGGG'), (102, 'HHHHH'), (210, 'IIIII')
SELECT
*
, ColN = (SeqOrder-1) %3
, RowN = (SeqOrder-1) / 3
FROM (SELECT *, ROW_NUMBER() OVER(ORDER BY Seq) AS SeqOrder FROM #t) t
The inner query just assigns the SeqOrder as 1 thru 9. We then use this SeqOrder value to determine the row and column
This gives us the following dataset
Then we just add a matrix to our report
Next, drag the ColN field to the "Columns" placeholder, the RowN field to the "Rows" placeholder and the Label field (or whatever field you want to display) to the "Data" placeholder.
Run the report and you get this
Optionally, you can remove the first row and column (but NOT the associated group) and just leave the data cell.
Now when we run it, we get this.
Related
I have a report with the differnet projects and with columns of values, etc. The thing that i'm looking for and i failed many times is i want to create a auto multi circle chart by project having only 3 charts per row and infinite rows depending of the projects that i have.
I have taken a look to this example but it doesnt work in me report
Dynamic control of number of charts in SSRS reports
Example
This is the visual chart example for one project
Example Project A
What i want to take, is an automatic multi chart that copy and paste this example chart for each a project creating a grid with 3 columns (to limit the width of the SSRS) and the necessary rows to complete all projects
Result that i want
Example multichart
Can someone help me on this? i'm stuck on this
You can do this without using subreports. You first determine a row and column for each project and then use a matrix to display the results.
I've mocked up some data for the purpose of this example which you will have to update to suit your needs.
DECLARE #t TABLE (Project varchar(10))
INSERT INTO #t VALUES ('A'), ('B'), ('C'), ('D'), ('E'), ('F'), ('G'), ('H')
DECLARE #prjData TABLE (Project varchar(10), N INT, U INT, C INT, S INT)
INSERT INTO #prjData VALUES
('A', 10, 20, 30, 40),
('B', 11, 21, 31, 37),
('C', 12, 22, 32, 34),
('D', 13, 23, 33, 31),
('E', 14, 24, 34, 28),
('F', 15, 25, 35, 25),
('G', 16, 26, 36, 22),
('H', 17, 27, 37, 19)
SELECT pd.*, rc.iCol, rc.iRow FROM #prjData pd
JOIN (
SELECT
*
, iRowNumber = ROW_NUMBER() OVER(ORDER BY Project)
, iCol = ((ROW_NUMBER() OVER(ORDER BY Project)-1) % #MaxCols)
, iRow = CAST(((ROW_NUMBER() OVER(ORDER BY Project)-1) / #MaxCols) as INT)
FROM #t
) rc on pd.Project = rc.Project
The inner query (alias rc) works out the row and column number for each project and then we just join that to your existing data. table variable #t will be replaced by your own table containing a list of projects.
#MaxCols is a simple variable that you can use to adjust the number of columns if you need to, or your can just hardcode this value. In the output below I used '3'. I've not declared this in the query as this will be passed from the report as a parameter.
N, U C and S are to represent your 4 values in your chart.
This gives us the following results.
Now we have our dataset, add a matrix control, drag iRow from the dataset fields to the "Rows" placeholder, iCol to the "Columns" placeholder and in the "Data" placeholder insert a pie chart.
Resize the Chart cell to suit your needs...
Now click the chart and set the values, series etc as desired.
Set the chart title to the Project field (in this case it's just a letter)
You report design will look something like this..
When you run the report you should get something like this...
Here is the same report again with MaxCols set to 4
Finally you can remove the redundant rows/columns if required
I have a matrix table with a column group "Application questions" let's say these are in table 1. Some of the questions have unique string values such as: Name, ID number, email address. But others have an integer value that relates to an actual value for a separate lookup table (table 2), for example, the values for the column "Gender" are 1, 2, 3, for Male, Female, Other. Is there a way in the lookup function that I can isolate the columns that only have integer values or alternatively ignore the other columns with unique string values?
Table1
NAME ATTRIBUTE_id ATTRIBUTE
-----------------------------------------
James 5 1
James 6 james#email.com
James 7 8
Table2
Lookup_id ATTRIBUTE_id Description
-----------------------------------------
1 5 Male
2 5 Female
3 5 Other
8 7 New York
9 7 Los Angeles
Output
NAME | Email | Gender | City
-------------------------------------------------------
James james#email.com Male New York
Hope that makes sense!
Thank you.
I think this will be easier to do in your dataset query.
Below I have recreated your sample data and added an extra person in to make sure it's working as expected.
DECLARE #t TABLE (Name varchar(10), AttributeID INT, AttributeMemberID varchar(50))
INSERT INTO #t VALUES
('Mary', 5, '2'),
('Mary', 6, 'Mary#email.com'),
('James', 5, '1'),
('James', 6, 'james#email.com'),
('James', 7, '8')
DECLARE #AttributeMembers TABLE (AttributeMemberID INT, AttributeID int, Description varchar(20))
INSERT INTO #AttributeMembers VALUES
(1, 5, 'Male'),
(2, 5, 'Female'),
(3, 5, 'Other'),
(8, 7, 'New York'),
(9, 7, 'Los Angeles')
I also added in a new table which describes what each attribute is. We will use the output from this as column headers in the final SSRS matrix.
DECLARE #Attributes TABLE(AttributeID int, Caption varchar(50))
INSERT INTO #Attributes VALUES
(5, 'Gender'),
(6, 'Email'),
(7, 'City')
Finally we join all three togther and get a fairly normalised view for the data. The join is a bit messy as your current tables use the same column for both integer based lookups/joins and absolute string values. Hence the CASE in the JOIN
SELECT
t.Name,
a.Caption,
ISNULL(am.[Description], t.AttributeMemberID) as Label
FROM #t t
JOIN #Attributes a on t.AttributeID = a.AttributeID
LEFT JOIN #AttributeMembers am
on t.AttributeID = am.AttributeID
and
CAST(CASE WHEN ISNUMERIC(t.AttributeMemberID) = 0 THEN 0 ELSE t.AttributeMemberID END as int)
= am.AttributeMemberID
ORDER BY Name, Caption, Label
This gives us the following output...
As you can see, this will be easy to put into a Matrix control in SSRS.
Row group by Name, Column Group by Captionand data cell would beLabel`.
If you wanted to ensure the order of the columns, you could extend the Attributes table to include a SortOrder column, include this in the query output and use this in SSRS to order the columns by.
Hope that's clear enough.
I have a table in SSRS that has both row and column groups.
For each row group [Cat], I need to highlight the highest value in the column group, which is the sum of all counts for that category in a given month.
Can't for the life of me figure it out, so if anyone could help that would be great!
Thanks
Example of dataset
This is what I'm aiming for
Table in Design View
Current outcome
The problem you will face is that you will have to try to use nested aggregates with scopes defined. This might be possible (but I don't think it is...)
There is a fairly simple way to fix it though. I can;t give an exact answer as I don;t know what your dataset looks like but typically you would have to make some changes to your dataset, then its simple.
So assuming your dataset looks something like this
Cat myDate counts
A 20171001 90
A 20171001 6
B 20171001 18
C 20171001 1
A 20171101 100
A 20171101 20
....
....
Then aggregate everything so the report does not have to do any real aggregation with something like
SELECT
*
, max(counts) OVER(PARTITION BY Cat) as maxInCat
FROM (
SELECT
Cat, myDate
, SUM(counts) as counts
FROM myTable
GROUP BY Cat, myDate
) x
This will give you a dataset with an additional column maxInCat. This column will contain the maximum value in each category so we can compare against this in the report.
The expression can then be something like
=IIF(SUM(Fields!counts.Value)>0 and SUM(Fields!counts.Value) = Fields!maxInCat.Value, "Yellow", Nothing)
EDIT
I've updated the actual backcolor expression as it didn't account for blanks/zeros
Ignoring the fact the the columns are not sorted as I don't have time, here's the result
Here's an answer that I think does what you need:
declare #Table as table
(
[Cat] char(1),
[Sector] tinyint,
[Counts] int,
[Date] date
);
insert into #Table
(
[Cat],
[Sector],
[Counts],
[Date]
)
values
('A', 1, 4103, '2017-10-01'),
('A', 1, 3001, '2017-11-01'),
('A', 1, 1128, '2017-12-01'),
('A', 1, 5917, '2018-01-01'),
('A', 1, 9594, '2018-02-01'),
...
So you know where the data is coming from.
with [AggregatedData] as
(
select
t.Cat,
t.Sector,
t.Counts,
t.[Date],
sum(t.Counts) over (partition by t.Cat, t.[Date]) as [SumCounts]
from #Table as [t]
)
select
ad.Cat,
ad.Sector,
ad.Counts,
ad.[Date],
ad.SumCounts,
max(ad.SumCounts) over (partition by ad.[Date]) as [MaxSumCounts]
from [AggregatedData] as [ad]
Then in SSRS, you can use:
=iif(IsNothing(Fields!SumCounts.Value) = FALSE AndAlso Fields!SumCounts.Value = Fields!MaxSumCounts.Value, "Yellow", "Transparent")
Which gives:
I have details, subtotals and totals.
When I put avg function in totals line I have avg of every row.
I need avg of subtotals
How to do it?
week1
day1..... 2
day3..... 3
day4..... 4
day6..... 2
total.... 11 sum()
week2
day1..... 3
day2..... 2
total..... 5 sum()
Total
........... 16 sum() OK
............ 2,66666 avg() here should be (11+5)/2 =8
Result after implementing solution
I created a dataset to replicate your sample data as follows:
DECLARE #t TABLE (week int, day int, amount int)
INSERT INTO #t VALUES
(1, 1, 2),
(1, 3, 3),
(1, 4, 4),
(1, 6, 2),
(2, 1, 3),
(2, 2, 2)
SELECT * FROM #t
I then built a simple tablix as you had done (more or less)
I included the incorrect results you had for illustration and then added a new expression to calculate this correctly.
The result looks like this
You can ignore the other datasets, this is just a report I use for testing. Only dataset3 is used here.
The expression used was this
=Sum(Fields!amount.Value) / CountDistinct(Fields!week.Value)
You'll just need to edit this to match your field names. It basically just sums all the detail amounts then divides by the number of distinct weeks in the dataset.
I have a table right now that has a list of numbers (some repeating) that goes from 0 to 350.
Is it possible to write a query in Microsoft Access to return how many numbers in the set belong to a range?
For example, if the set of data is 0, 1, 2, 3, 4, 5, 6, 7, I want to create a query to return how many numbers below to the range between 3 and 6 (inclusive). In this example, it would return 4 since the numbers 3, 4, 5 and 6 are in this range.
Thanks.
Have you ever used the 'COUNT' function in a query?
If not, use the query builder to select your number column TWICE from the table.
Add a criteria on your range of 3 to 6.
Set the query to 'Totals' see toolbar), then change your Criteria column to 'WHERE' (in the 'Totals' row),and change the other column to 'COUNT' (in the Totals row)
i.e
SELECT Count(Table1.ID) AS CountOfID
FROM Table1
WHERE (((Table1.ID) Between 1 And 15));