Count number of row results for a row group - reporting-services

How do I group/filter rows and then get total rows for each column. I am going to diagram what the result should be. I don't want to show the actual data. Just the count per column
Out Put should look like this
Column A Column B Column C
Row A - 235 records 300 records 15 records
Row B - 1 record 80 records 900 records
Each column represent a count on the same field but filtered.
So ..
Column A is really Count(MyColumn) WHERE = A
Column B is really Count(MyColumn) WHERE = B
To summarize each row is a grouping + filter and each column is a count based on the number of rows contained in that grouping. No row data needs to be displayed.

You can do this in a table in the group by using the following formula:
=SUM(IIF(Fields!MyColumn.Value = "A", 1, 0))
However, this type of summary report is what a matrix is designed to do. Use the Row field as the row group, the column field as the column group and a Count expression in the intersection and it will do it all for you.

Related

SSRS, return rows into a grid layout

I have a dataset that I need to arrange into a grid on a page (export to pdfs) as a customer report. Each row in my dataset needs to display as a cell. Each page would have roughly 3 records displayed as columns and then 4 rows of records. e.g. a (3x4 grid), being 12 records per page.
Right now I am using a matrix to display my results, but I cannot find how to get my matrix to start a 2nd row after 3 columns are generated.
Is this feasible or should I find a different solution to create these reports?
I was thinking may be if I had row groups to use, but not sure how to create a column that creates a repeating result 3 times then adds 1 to the next 3 results in my query. 111,222,333,444 and that could be my row grouping?
Here's what I use in a matrix to create a grid of columns from a single cell.
Add a ROW_NUMBER field to the dataset query and subtract 1 with the ORDER BY using the field to be ordered by.
ROW_NUMBER()OVER(ORDER BY DISPLAY_NAME) - 1 AS ROW_NUM
Add Calculated Fields to the dataset using the ROW_NUM.
Call the first COLUMN and MOD row_num by 3 to get values or 0 - 2 for the column number:
=Fields!ROW_NUM.Value MOD 3
Call the second calculated field ROW and get the INT of ROW_NUM divided by 3 to get the row number for the record:
=INT(Fields!ROW_NUM.Value / 3)
Then the matrix would have the Column grouping (and sorting) based on the COLUMN field and the Row grouping on the ROW field.
You could use a parameter as the number of columns (3) to make it easy to change.

Update a column based on the highest value from another column

I have a SQL-database with a table called 'PP_Match' with a couple of columns in it.
ID, Position_1, Position_2, Round and Draw_size
In this table ID, Position_1 and Position_2 is a composite key together!
I want to update the Draw_size column, based upon the highest value in column 'Round'. To make this extra fun, the Draw_size column should display a knock-out draw (Elimination Draw), that you use in any kind of sport.
So if the highest value in Round for a specific ID is 1, then I want to display '2' in Draw_size. If the highest value is 2 then draw_size is 4, and a 3 in Round column would return a 8 in draw_size and so on (4=16, 5=32, 6=64, 7=128).
I want to update all rows of a specific ID.
Let say that ID 001 has 5 rows in the database with the higest value in "Round" as 3, then I want to update all the 5 rows with a Draw_size value of 8...
I've tried and failed multiple times...
Thank you guys for your assitance!!!
/ Fred
Something like that should work
UPDATE PP_MATCH pp1
LEFT JOIN (
SELECT ID, MAX(ROUND) as Max_Round FROM PP_MATCH GROUP BY ID) A
ON A.ID = pp1.ID
SET pp1.Draw_size = POW(2, Max_Round)

Google Spreadsheet function Query

I am confused.
I have a spreadsheet in google with 2 tables.
I want to select data from a sheet named "Presseverteiler" where a value in one field equals the value that I enter in a second sheet named "Veröffentlichungen". The formula is inside the sheet "Veröffentlichungen".
My code is this
=IF(not(isblank(D2)) ; QUERY(Presseverteiler!$A$2:AZ;"SELECT F WHERE A="&D2&" LIMIT 1"); "")
D2 is a number in "Veröffentlichungen" that equals a number in "Presseverteiler" in column A.
If the numbers in column A are not sorted from A to Z (1 to 510 in my case), the query yields the result I want.
If the numbers in column A are in order though, the query gives the result I want plus the entry of line 2 which it puts ahead of the result I want.
If I want entry 223 it would give 2 and then 223. To make it more weird: I have many other columns. Depending on if I sort those by A-Z or Z-A some of them give me 1 result in the query, some give me 2 results. Some give me 1 result both ways.
For example if I sort "title" A-Z (contains Mr, Mrs, Dr.) I get 2 results, if I sort the same column Z-A I get one result.
If I order the column "publication" A-Z or Z-A I get one result.
Despite all that, why does the LIMIT 1 not work here? Even with that I get a #REF! error that the results can not be displayed because they would overwrite successive fields in the table.

SQL query for operation between rows under some condition

Its little complicated query as it contains some conditions.
I have tables like this:
table DC - which contains one row for one northing-easting pair
Columns - Id Northing Easting
PossibleValues - Guid Std value Std value
table DCR - which contains multiple rows for each row in DC. Each row here corresponds to data on each pass on that exact location.
Columns - Id VibStatus DrivingDir CompactionValue UtcDate
PossibleValues - Guid 0/1 Forward/Reverse/Neutral +ve integers Timestamp
table DCMappings - which contains mapping between both tables.
DCId DCRId
The output I need should contain fields like this:
ResultTable
DCId DCRId Northing Easting VibStatus DrivingDir CompValue Position CompProgress
Here, Position is its position in chronological order when sorted by UtcDate grouped by DC.Id(See query at end to understand more).
And CompProgress has some conditions which is making it complicated.
CompProgress is percentage increase/decrease in CompValue compared to its previous row which was in same driving direction when arranged in ASC order of UtcDate(chronological) where the rows to be considered here should only be the ones with VibStatus set to ON(1) grouped by DCId's.
Each row in DC has multiple rows in DCR. So if row 1 in DC has 10 rows in DCR, the CompProgress should consider these 10 rows alone for calculation and then for row 2 in DC, etc...
I have written following query to extract needed fields except calculation of CompProgress. Please help me in this.
SELECT DC.Id, DCR.Id, Northing, Easting, VibStatus, DrivingDir, CompValue, ROW_NUMBER() OVER (PARTITION By dcm."DCId" ORDER BY dcr."UtcDate") as passNo
FROM "DCR" dcr LEFT JOIN "DCMappings" dcm ON "Id" = dcm."DCRId"
LEFT JOIN "DC" dc ON dc."Id" = dcm."DCId"
Need evaluation of CompProgress in this query.
Sorry for lot of text. But it was necessary to make others understand what is needed.

Adding Value Fields in a different data set in SSRS

In this question it answered how to add two different datasets,
SSRS - Expression using different dataset fields
I tried that kind of approach and here is my expression
=First(Fields!count.Value, "remclass1")+First(Fields!count.Value, "db_IACS")
the problem is that only the first value is being Calculated like this
I added the Pulled out COUNT to the Expired Count, i want it to be added per Row
only the first part
For instance:
Column 7 (Count) = Column1(Count) + Column 4 (count) //**per Row**
The value of row 1 column 7 would be column 1 + column 4 row 1
the value of row 2 column 7 would be column 1 + column 4 row 2
The Pulled out table
(Consists of Count, Grams, Principal) are on the data set db_IACS
and the Expired table(Consists of Count,Grams,Prinicipal) are in the dataset remclass1
So any help how to do it? how to add the two columns (in a different dataset)
Thanks :)
You could do this in SQL, as follows:
SELECT db_IACS.count as PulledOut_Count, db_IACS.Grams AS PulledOut_Grams, db_IACS.Principle AS PulledOut_Principle,
remclass1.count as remclass1_Count, remclass1.Grams AS remclass1_Grams, remclass1.Principle AS remclass1_Principle
FROM db_AICS
LEFT OUTER JOIN remclass1 ON db_IACS.Id = remclass1.Id
Then just deal with everything in the one dataset.