Show total from column group as row - reporting-services

Im trying to get a row with the total for a column group with SSRS. This is my report:
+-----------+---------------------------+--------------------------+--------------+
| | John Doe | Brody Shaffer | Kerry Morrow |
+-----------+-------------+-------------+-------------+------------+--------------+
| Date | Project 1 | Project 2 | Project 3 | Project 5 | Project 4 |
| 1/1/2020 | $ 2.512,20 | $ 3.230,00 | $ 0 | $ 0 | $ 200,00 |
| 2/1/2020 | $ 0 | $ 0 | $ 35.504,00 | $ 5.200,30 | $ 3.400,00 |
| 5/1/2020 | $ 6.640,90 | $ 987,00 | $ 1.879,00 | $ 0 | $ 0 |
| 15/1/2020 | $ 650,50 | $ 0 | $ 0 | $ 0 | $ 0 |
.
.
.
I want this row:
.
.
.
+-----------+-------------+-------------+-------------+------------+--------------+
| Total | $ 14.020,6 | $ 42.583,3 | $ 3.600,00 |
+-----------+---------------------------+--------------------------+--------------+
Rows sample:
+---------------+-----------+-----------+-------------+
| Customer | Date | Project | Budget |
+---------------+-----------+-----------+-------------+
| John Doe | 1/1/2020 | Project 1 | $ 2.512,20 |
| John Doe | 1/1/2020 | Project 2 | $ 3.230,00 |
| John Doe | 5/1/2020 | Project 1 | $ 6.640,90 |
| John Doe | 5/1/2020 | Project 2 | $ 987,00 |
| John Doe | 15/1/2020 | Project 1 | $ 650,50 |
| Brody Shaffer | 2/1/2020 | Project 3 | $ 35.504,50 |
| Brody Shaffer | 2/1/2020 | Project 5 | $ 5.200,30 |
| Brody Shaffer | 5/1/2020 | Project 3 | $ 1.879,00 |
| Kerry Morrow | 1/1/2020 | Project 4 | $ 200,00 |
| Kerry Morrow | 2/1/2020 | Project 4 | $ 3.400,00 |
+---------------+-----------+-----------+-------------+
This is my row group:
Date
This is my column group:
Customer
Project
When i add a "total" for the "Customer group", visual studio add a new column, but i need a new row with the total data.
Is this possible?

I don't think it's possible to get exactly what you want because, as far as I know, you cannot merge cells across column groups. However, we can get close.
There are two ways to do this.
Option 1: This is simplest but means the totals appear between the Customer Name and the project name. T do this simply right click the "Customer name" cell and do "Insert Row => Inside Row - Below". Set expression simply to
=Sum(Fields!Budget.Value)
Option 2: This is a little more work but gets closer to your desired output.
First, right-click a cell in your detail row and do "Insert Row => Outside group - Below"
In the new row, set the cell expression to
=Sum(Fields!Budget.Value, "Customer")
We include the scope "Customer" so all values within the customer column group are summed, if you omit this scope then it would only aggregate within each project.
If you run the report you'll see that you have duplicate numbers but we only want to show one. We can solve this by checking if the project column matches the first project column within the customer group.
Change the cell expression from what we just set to this..
=IIF(
FIRST(Fields!Project.Value) = FIRST(Fields!Project.Value, "Customer"),
Sum(Fields!Budget.Value, "Customer"),
Nothing
)
Now we only get the value shown once but there is a visible line between the cells , we can solve this in a similar way.
In the cell properties, leave the BorderStyle - Default as "Solid" but change the BorderStyle - Left to "None".
Next set the BorderStyle - Right property to the following expression.
=IIF(
FIRST(Fields!Project.Value) = FIRST(Fields!Project.Value, "Customer"),
"None",
"Solid"
)
What this does is check if the project matches the first project within the customer (i.e. the left column) and sets the border style accordingly.
The final output should be what you want except the Sum budget value will look offset to the left.
I'm not sure if there is better solution though...
Here's the final design and output with both Options 1 and 2 shown.
Design view
Output

At the bottom of Visual Studios, there should be a "Row Groups" and "Column Groups" breakdown of your matrix. Select your matrix and this should populate with applicable groups in your matrix. Right click on the record where you want the total in the "Row Groups" section and click the "Add Total" option then you just have to pick if you want the total row to be before or after your data.

Related

SSRS report - pivoting data (last columns grouping)

I am trying to achieve the attached prototype for ssrs report. I was able to get all the data but can not figure out how to show the last three columns ("First Time Posted", "Last Time Cancelled" and "Total Duration")
When i try with expression it show data for every single corresponding line, just want to show one entry based on group.
Thank you,
Desired output
Report design
Data will be like
| Cp Label | Time Posted | Time Cancelled| Duration | Link ID|
---------------------------------------------------------------------
| Cp 1 | 12:56:00 | 12:57:05 | 00:01:05 | 1 |
---------------------------------------------------------------------
| Cp 2 | 12:57:05 | 1:00:00 | 00:02:55 | 1 |
---------------------------------------------------------------------
| Cp 3 | 12:57:00 | 1:15:00 | 00:18:00 | 2 |
---------------------------------------------------------------------

pyqt4 - MySQL How print single/multiple row(s) of a table in the TableViewWidget

I've recently tried to create an executable with python 2.7 which can read a MySQL database.
The database (named 'montre') regroups two tables : patient and proto_1
Here is the content of those tables :
mysql> select * from proto_1;
+----+------------+---------------------+-------------+-------------------+-----
----------+----------+
| id | Nom_Montre | Date_Heure | Temperature | Pulsion_cardiaque | Taux
_oxy_sang | Humidite |
+----+------------+---------------------+-------------+-------------------+-----
----------+----------+
| 1 | montre_1 | 2017-11-27 19:33:25 | 22.30 | NULL |
NULL | NULL |
| 2 | montre_1 | 2017-11-27 19:45:12 | 22.52 | NULL |
NULL | NULL |
+----+------------+---------------------+-------------+-------------------+-----
----------+----------+
mysql> select * from patient;
+----+-----------+--------+------+------+---------------------+------------+----
----------+
| id | nom | prenom | sexe | age | date_naissance | Nom_Montre | com
mentaires |
+----+-----------+--------+------+------+---------------------+------------+----
----------+
| 2 | RICHEMONT | Robert | M | 37 | 1980-04-05 23:43:00 | montre_3 | ess
aye2 |
| 3 | PIERRET | Mandy | F | 22 | 1995-04-05 10:43:00 | montre_4 | ess
aye3 |
| 14 | PIEKARZ | Allan | M | 22 | 1995-06-01 10:32:56 | montre_1 | Hea
lthy man |
+----+-----------+--------+------+------+---------------------+------------+----
----------+
As I'm just used to code in C (no OOP), I didn't create class in the python project (shame on me...). But I managed, in two files, to create something (with mysql.connector) which can print (on the cmd) my database and excecute sub like looking-for() etc.
Now, I want to create a GUI for users with pyqt. Unfortunately, I saw that the structure is totally different, with class etc. But okay, I tried to go throught this and I've created a GUI which allows to display the table "patient". But I didn't manage (in the datasheet of QT) to find how I can use the programs I've already created to display. Neither how to display in a tableWidget only several rows of my table patient for exemple (Using QSQL).
For example, if I want to display all the table patient, I use this line (pyQt):
self.model.setTable("patient")
For this one, I got it, but that disturb me because there is no MySQL coding requisites to display my table and so I don't know how to sort only the rows we want to see and display them. If we only want to see, for example, the ID n°2, how to display in the table:widget only Robert ?
To recap, I want to know :
If I can take the coding I've created and combine it with pyQT
How to display (tableWidget) only rows which are selected by MySQL. Is that possible ?
Please find in the URL my code for a better understanding of my problem :
https://drive.google.com/file/d/1nxufjJfF17P5hN__CBEcvrbuHF-23aHN/view?usp=sharing
I hope I was clear, thank you all for your help !

SSRS: how to display grouped rows in different cells of a list

The dataset returns rows of the below shape.
+------------+---------------+-------------------+----
| Department | Full Name | Bonus Recommen (%) |
+------------+---------------+-------------------+----
| Accounting | Jane Doe | 3.00 |
+------------+---------------+-------------------+----
| Accounting | Phil Morris | 1.05 |
+------------+---------------+-------------------+----
| Accounting | Aimee Jackson | 1.27
+------------+---------------+-------------------+----
| Production | Paul McDonald | 2.47
+------------+---------------+-------------------+----
| Production | John Doe | 1.98
+------------+---------------+-------------------+----
I'd like to individual tables depending on the department, i.e. something like this:
+------------------------------------------
| Accounting
+---------------+--------------------+----
| Full Name | Bonus Recommen (%) |
+---------------+--------------------+----
| Jane Doe | 3.00 |
+---------------+--------------------+----
| Phil Morris | 1.05 |
+---------------+--------------------+----
| Aimee Jackson | 1.27 |
+---------------+--------------------+----
+------------------------------------------
| Production
+---------------+--------------------+----
| Full Name | Bonus Recommen (%) |
+---------------+--------------------+----
| Paul MacDonald| 2.47 |
+---------------+--------------------+----
| John Doe | 1.98 |
+---------------+--------------------+----
Thanks for helping
You can get the layout by grouping:
add a table and drop fullname and bonus into the table. Remove the
extra blank column since RS will create 3 column table by default
At the bottom of the IDE right click row groups and click Add Group
-> Parent Group, and select Department from the dropdown list
Right click the Department cell at data row level, from context menu
select Insert Row -> Inside Group - Above
Copy the cell title (or simply input Full Name and Bonus) to this newly added row
Repeat step 3 to add another row
Select two cells from newly added row, right click and click Merge
Cells
Copy Department cell value to this merged cell
right click the left most column (department) and select Delete Columns
Hope it helps.

Different value counts on same column using LIKE

I have a database like below
+------------+---------------------------------------+--------+
| sender | subject | day |
+------------+---------------------------------------+--------+
| Darshana | Re: [Dev] [Platform] Build error | Monday |
| Dushan A | (MOLDOVADEVDEV-49) GREG Startup Error | Monday |
+------------+---------------------------------------+--------+
I want to get the result using the above table. It should check if the subject contains the given word then add one to the that word column for a given day.
|Day | "Dev" | "startup"|
+---------+------------+----------+
| Monday | 1 | 2 |
| Friday | 0 | 3 |
I was thought of using DECODE function but I couldn't get the expected result.
You can do this with conditional aggregation:
select day, sum(subject like '%Dev%') as Dev,
sum(subject like '%startup%') as startup
from table t
group by day;

failed matching regex in mysql

I'm having a query problem. I use MySQL as DB. I want to use a REGEX to match the result I expected and the Table is:
table A
-----------------------------------------------
| ID | Description |
-----------------------------------------------
| 1 | 29th Marine Regiment/1st Bn (1/29) |
| 2 | new 21 new 2 new |
| 3 | new 2th 2 (2/2) |
| 4 | 2new 2new (2/2) |
| 5 | new2 new 2new |
The result I need to get :
-----------------------------------------------
| ID | Description |
-----------------------------------------------
| 1 | 29th Marine Regiment/1st Bn (1/29) |
I have the correct result for regex
^(29[^0-9]+)[^0-9]+1[^0-9]+\([a-zA-Z0-9/-]*\)\s*$
in http://www.regexr.com/ but I don't get the result in MySQL.
http://sqlfiddle.com/#!2/7bd4b/2
Does anyone know how this happen?
(Turning my comment into an answer.)
You need to escape backslashes! E.g. \( → \\(.
And there are some other issues:
The group in the beginning is not used anywhere, so it can be removed.
[^0-9]+[^0-9]+ (once the group has been removed) is rather redundant. It can be shortened to [^0-9]{2,}, but in this case it looks like [^0-9]+ will suffice.
The fiddle version had some strange {}s that had to be removed.
The result is thus:
'^29[^0-9]+1[^0-9]+\\([a-zA-Z0-9/-]*\\)\\s*$'