SSRS report - pivoting data (last columns grouping) - reporting-services

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 |
---------------------------------------------------------------------

Related

Merge duplicate (row group) column cells

ID| Date1 | Date 2 |Total
-----------------------------------
1 | 15/02/2017 |02/02/2017 | 3 |
-----------------------------------
1 | 15/02/2017 |05/08/2017 | 3 |
-----------------------------------
1 | 15/02/2017 |12/12/2017 | 3 |
-----------------------------------
2 | 12/05/2017 |07/08/2017 | 2 |
-----------------------------------
2 | 12/05/2017 |10/08/2017 | 2 |
I have a table that is displaying data like above. I'm grouping that data on "ID" column. Values for Columns "Date1" & "Total" for a particular "ID" are the same but "Date2" value can be different in a given group.
How can i merge the cells across rows when the values are the same such that it displays like below?
ID| Date1 | Date 2 |Total
-----------------------------------
1 | 15/02/2017 |02/02/2017 | 3 |
--| |------------| |
1 | |05/08/2017 | |
--| |------------| |
1 | |12/12/2017 | |
---------------------------------|
2 | 12/05/2017 |07/08/2017 | 2 |
--| |------------| |
2 | |10/08/2017 | |
I did manage to find that "HideDuplicates" TextBox property, but while that will suppress the repetition of the cell values in adjacent rows it does not merge those duplicate cells down the column across rows
Its difficult to tell how the report is setup in terms of groups etc without seeing the design, but this is pretty simple to do from scratch.
Start with a simple table with just your detail rows, no grouping. Then right-click the detail row in the row group panel under the main report design area. Choose Add Group -> Parent Group
Choose your Date1 field in the group by drop down . Click OK and you're done.

Group results in Crystal Reports where linked column has multiple related results

I have two tables that are linked. The first table is a list of prescribed medications ('medications' table) and the other is a list of actions that relate to the medication when it has been prescribed ('PMP' table)
For each prescribed medication, there can be multiple actions such as authorise, comment, stop etc.
What i am trying to do is to call all prescribed medications along with every other action for that drug.
I can do this using the code below.
select medications.oid, medications.drug, PMP.action_dte, PMP.actions
from medications
left join PMP on medications.oid = PMP.fk2_oid
This works fine and i get everything i need. But the medications that have multiple actions are returned once for each action.
My issue comes when i want to put it in to a Crystal Report.
I have a subreport called Drugs and i want to list all of the authorised drugs on the left and then all the actions for that drug on the right. But what i get is.
OID | MEDICATION | ACTION DTE | ACTION
| | |
1 | Paracetamol 200mg | 01.01.17 | Authorised
| | |
| | |
1 | Paracetamol 200mg | 03.01.17 | Comment
| | |
| | |
1 | Paracetamol 200mg | 10.01.17 | Stop
| | |
| | |
2 |Ibuprofen 100mg | 05.01.17 | Authorised
| | |
| | |
2 |Ibuprofen 100mg | 06.02.17 | Comment
Where as i would like
OID | MEDICATION | ACTION DTE | ACTION
| | |
1 | Paracetamol 200mg | 01.01.17 | Authorised
| | 03.01.17 | Comment
| | 10.01.17 | Stop
| | |
2 | Ibuprofen 100mg | 05.01.17 | Authorised
| | 06.02.17 | Comment
| | |
I have played around with grouping by oid and fk2_oid. As well as trying to link two sub reports on those fields but i am getting no where.
Is anyone able to suggest a formula or preferably a modification to the code which will allow the crystal report to display the drug on the left ONCE along with every action related to that drug on the right.
Thanks in advance!
EDIT ----------
I forgot to mention that there is a date field in the equation. Which is PMP.action_dte. Edited the original query and description.
Apologies for any confusion caused.
EDIT 2 ---------
Apparently my original post was misleading.....modified to hopefully clarify. I would like the drug grouped by OID with every action allocated to that drug listed along with the action date, as shown above.
Bring in your results
Under Report > Group Expert, group by Drug.
Then I deleted Drug in Details
In Group Header 1, Section Report, check on Underlay Following
Section
Remove Bold for Group #1 Medication
You can download the Crystal Report here

Multiple Data Sources in Microsoft Excel SQL Query

I have a lot of spreadsheets that pull transactional information from our ERP software into Excel using the Microsoft Query that we then perform other calculations on automatically. Recently we upgraded our ERP system, but management made the decision to leave the transactional history in the old databases to have a clean one going forward in the new system. I still need to have some "rolling 12 months" graphs, but if I use only the old database, I'm missing new data and if I use only the new, I'm missing the last 11 months data.
Is there a way that I can write a query in Excel to pull data from the old database PartTran table and merge it with the new database PartTran table without user intervention each time? For instance, I don't want my users (if possible) to have to have two queries that they copy and paste into one Excel table. The schema of the tables (at least the columns I need) are identically named and defined.
If you want to take a bit of a fun, hacky Excel approach, you could do the "copy-paste" bit FOR your users behind the scenes. Given two similar tables OLD and NEW with structures
+-----+------+-------+------------+
| id | foo | bar | date |
+-----+------+-------+------------+
| 95 | blah | $25 | 2015-06-01 |
| 96 | bork | $12 | 2015-07-01 |
| 97 | bump | $200 | 2015-08-01 |
| 98 | fizz | | 2015-09-01 |
| 99 | buzz | $50 | 2015-10-01 |
| 100 | char | ($1) | 2015-11-01 |
| 101 | mope | | 2015-12-01 |
+-----+------+-------+------------+
and
+----+-----+-------+------------+------+---------+
| id | foo | bar | date | fizz | buzz |
+----+-----+-------+------------+------+---------+
| 1 | cat | ($10) | 2016-01-01 | 285B | 1110111 |
| 2 | dog | $25 | 2016-02-01 | 27F5 | 1110100 |
| 3 | ant | $100 | 2016-03-01 | 1F91 | 1001111 |
+----+-----+-------+------------+------+---------+
... you can union together the data for these two datasets with some prudent excel wizardry as below:
Your UNION table ( named using alt+j+t+a ) should have the following items:
New natural ID
DataSet pointer ( name of old or new table )
Derived ID from original dataset
Columns of data you want from Old & New DataSets
example:
+---------+------------+------------+----+------+-----+------------+------+------+
| UnionId | SourceName | SourceRank | id | foo | bar | date | fizz | buzz |
+---------+------------+------------+----+------+-----+------------+------+------+
| 1 | OLD | | | | | | | |
| 2 | NEW | | | | | | | |
+---------+------------+------------+----+------+-----+------------+------+------+
You will then make judicious use of Indirect() and VlookUp() to derive the lookup id and column targets. Sample code below
SourceRank - helper column
=COUNTIFS([SourceName],[#SourceName],[UnionId],"<="&[#UnionId])
id - the id from the original DataSet
=SMALL(INDIRECT([#SourceName]&"[id]"),[#SourceRank])
Everything else is just VlookUp madness!! Although I've taken the liberty of copying the sample code below for reference
foo =VLOOKUP([#id],INDIRECT([#SourceName]),MATCH(UNION[[#Headers],[foo]],INDIRECT([#SourceName]&"[#Headers]"),0),0)
bar =VLOOKUP([#id],INDIRECT([#SourceName]),MATCH(UNION[[#Headers],[bar]],INDIRECT([#SourceName]&"[#Headers]"),0),0)
date =VLOOKUP([#id],INDIRECT([#SourceName]),MATCH(UNION[[#Headers],[date]],INDIRECT([#SourceName]&"[#Headers]"),0),0)
fizz =VLOOKUP([#id],INDIRECT([#SourceName]),MATCH(UNION[[#Headers],[fizz]],INDIRECT([#SourceName]&"[#Headers]"),0),0)
buzz =VLOOKUP([#id],INDIRECT([#SourceName]),MATCH(UNION[[#Headers],[fizz]],INDIRECT([#SourceName]&"[#Headers]"),0),0)
Output
You'll likely want to make prudent use of If() and/or IfError() to help your users ignore the new column references to the old table and those rows that do not yet have data. Without that, however, you'll end up with something like the below.
This is both ready to accept & read new inputs to both OLD and NEW DataSets and is sortable to get rid of those pesky placeholder rows...
Hope this helps! Happy coding!

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;

Returning multiple results from one row

I have a set of MySQL data similar to the following:
| id | type | start | end |
===============================================================
| 1 | event | 2011-11-01T00:00:00 | 2012-01-02T00:00:00 |
| 2 | showing | 2012-11-04T00:00:00 | 2012-11-04T00:00:00 |
| 3 | conference | 2012-12-01T00:00:00 | 2012-12-04T00:00:00 |
| 4 | event2 | 2012-01-01T00:00:00 | 2012-01-01T00:00:00 |
I want to retrieve events within a certain date range, but I also want to return individual results for each row that has a time span of more than one day. What's the best way to achieve this?
EDIT: In other words, I want to return two results from the event row, four results from the conference row and a single result for all the others.
Any ideas would be greatly appreciated.
Try this statement:
SELECT * FROM table
WHERE START BETWEEN '2012-01-01' AND '2012-01-03'
OR END BETWEEN '2012-01-01' AND '2012-01-03'
OR TO_DAYS(end) - TO_DAYS(start) > 1
I have created it for testing on SQL Fiddle