Group Entire Crystal Report by Column in Subreport - sql

I am trying to set up the following report so that it is grouped first by "Transfer-In Unit" (d1_10.xinstitute), which is the title of a column that is included in a sub-report, and second by xpid, which is a patient index number used in all tables (except a catalog) in this report. To simplify this question, assume that xpid is indexed in alphabetical order of the patients' names.
See info/examples below:
This report shows patients that have transferred out of a specific unit since the user-inputted date (Name), a row for each date that the patient transferred out of a particular unit (Unit M Transfer-Out Date), chronologically where they next transferred into (Transfer-In Unit), and when they transferred into that unit (Transfer-In Date).
Currently without attempting this grouping the output looks like this:
Name and Unit M Transfer-Out Date are on the parent report
Transfer-In Unit and Transfer-In Date are in a subreport because they both call d1_10.dstartdate but with different criteria.
The goal is to sort by Transfer-In Unit, which is a column in the subreport.
The output should be:
An underlying issue is that to select the chronological next transfer-in following a transfer-out, I have to select a minimum transfer date grouped by xpid. This causes the requirement of an xpid grouping in the sub-report.
I have tried a grouping by d1_10.xinstitute (the unit index) in both the parent- and sub-reports. In the parent report it creates one all-encompassing group, because every row in this report represents someone transferring out of "Unit M". In the subreport it seems to apply the groupings row by row, so each row has two groups, even when the next row is the same patient transferring into the same unit. However this is my best attempt and it looks like this:
Any help/thoughts/ideas much appreciated. Let me know if I can provide any further info.
Thanks

Related

SSRS Group Subtotal and Total

I'm trying to get the subtotal for WO Total Cost but where that WO Number appears multiple time in the Division group I don't want to add them together. I only want the cost for WO Total to appear once in the report for each division. As it is now the work order number 40321 has a WO Total Cost of $362.24 and because it appears for each laborer it is added in the total represented in the green total line. Can anyone tell me how to prevent summing WO Total Cost where the WO Number appears more than once in a Division group?
Thanks for the reply Alan. Here is a screenshot of the design view in Report Builder. So, what I'd like to see is a summing of only the WO Total cost once for each report for each WO Number. The WO Total cost represents all costs (Equipment, Labor, and Material) for a given work order. So, at it stands now, the report is summing work order 40321 three times and giving us an incorrect total.
I've grouped the report by Division so we can see costs for a particular division for a given time period. I've also grouped the report by Person Labor so we can see how much a particular laborer is costing us for a given period of time.
What I don't know is how to do is prevent the report from summing the WO Total cost where the WO Number appears multiple times in the results for a given division.
I'm not sure you will be able to do this directly in the report design without some convoluted custom code. Other people maybe will have more inspiration but I can't see how to do it. You cannot even look for unique values to sum as it's possible that 2 WO numbers could have the same cost.
Without knowing what your dataset/database tables look like I can't offer much more but here are some approaches I might consider if I was doing this, both mean doing the work in SQL.
**Option 1 **
I would consider calculating this in your query in a new column which should be fairly simple. Each row would end up with the total amount for the AssetGroup. So, if you had 20 records for AssetGroup A and 10 records for AssetGroup B than all the 'A' records would have the same 'AssetGroupTotalWOAmount' value and all the 'B' records would have the same 'AssetGroupTotalWOAmount' value.
Then in your report you can simply use =FIRST(Fields!AssetGroupTotalWOAmount.Value) to get the correct number. This will get the first value within the scope of the expression, so your case within the ASSETGROUP row group.
**Option 2 **
Create a separate dataset with just the amounts you need, with a single record per AssetGroup . So probably just two columns, AssetGroup and AssetGroupTotalWOAmount
In the report you could then use a LOOKUP to get the correct value.

SAP BO - how to get 1/0 distinct values per week in each row

the problem I am trying to solve is having a SAP Business Objects query calculate a variable for me because calculating it in a large excel file crashes the process.
I am having a bunch of columns with daily/weekly data. I would like to get a "1" for the first instance of Name/Person/Certain Identificator within a single week and "0" for all the rest.
So for example if item "Glass" was sold 5 times in week 4 in this variable/column first sale will get "1" and next 4 sales will get "0". This will allow me to have the number of distinct items being sold in a particular week.
I am aware there are Count and Count distinct functions in Business Objects, however I would prefer to have this 1/0 system for the entire raw table of data because I am using it as a source for a whole dashboard and there are lots of metrics where distinct will be part/slicer for.
The way I doing it previously is with excel formula: =IF(SUMPRODUCT(($A$2:$A5000=$A2)*($G$2:$G5000=$G2))>1,0,1)
This does the trick and gives a "1" for the first instance of value in column G appearing in certain value range in column A ( column A is the week ) and gives "0" when the same value reappears for the same week value in column A. It will give "1" again when the week value change.
Since it is comparing 2 cells in each row for the entire columns of data as the data gets bigger this tends to crash.
I was so far unable to emulate this in Business Objects and I think I exhausted my abilities and googling.
Could anyone share their two cents on this please?
Assuming you have an object in the query that uniquely identifies a row, you can do this in a couple of simple steps.
Let's assume your query contains the following objects:
Sale ID
Name
Person
Sale Date
Week #
Price
etc.
You want to show a 1 for the first occurrence of each Name/Week #.
Step 1: Create a variable with the following definition. Let's call it [FirstOne]
=Min([Sale ID]) In ([Name];[Week #])
Step 2: In the report block, add a column with the following formula:
=If [FirstOne] = [Sale ID] Then 1 Else 0
This should produce a 1 in the row that represents the first occurrence of Name within a Week #. If you then wanted to show a 1 one the first occurrence of Name/Person/Week #, you could just modify the [FirstOne] variable accordingly:
=Min([Sale ID]) In ([Name];[Person];[Week #])
I think you want logic around row_number():
select t.*,
(case when 1 = row_number() over (partition by name, person, week, identifier
order by ??
)
then 1 else 0
end) as new_indicator
from t;
Note the ??. SQL tables represent unordered sets. There is no "first" row in a table or group of rows, unless a column specifies that ordering. The ?? is for such a column (perhaps a date/time column, perhaps an id).
If you only want one row to be marked, you can put anything there, such as order by (select null) or order by week.

Powerpivot one to many filter column

I have 2 tables, a visit table and then a diagnosis table. Visit is my one and diagnosis is my many (you can have secondary and tertiary diagnosis).
I have over 50 measures created in the visit table. Because of this, I simply want to create a flag on my visit table in the form of a column that will filter down my results based upon selections from the Diagnosis table. I have seen formulas for measures that use =calculate([cases],DXCodes) which will filter down the cases to only those that relate to the DXCodes and this works, but I don't want to have to build this in for every measure. Instead I want a DXFlag that will flag my visit rows with a 1 if what I selected from Diagnosis exists in the Visit table. Suggestions? I can get more specific if this is not making sense
Making some assumptions about your data, you could have tables like this:
And if you create a measure to pick out each of the diagnoses:
[diag1]:=FIRSTNONBLANK(Visits[Primary Diag],1)
[diag2]:=FIRSTNONBLANK(Visits[Secondary Diag],1)
[diag3]:=FIRSTNONBLANK(Visits[Tertiary Diag],1)
Then add this measure to flag your visit rows:
[Found]:=MAXX(ALLSELECTED(Diagnoses[Diagnosis]),IF(FIRSTNONBLANK(Diagnoses[Diagnosis],1)=[Diag1]||FIRSTNONBLANK(Diagnoses[Diagnosis],1)=[Diag2]||FIRSTNONBLANK(Diagnoses[Diagnosis],1)=[Diag3],1,BLANK()))
This gives you this result:
Edit: Response to revised/clarified requirements
I've been trying to see if I can get a calculated column to take account of the diagnosis selection with little success. Doing it with a measure is fairly straightforward:
[Diag Flag]:=IF(CALCULATE(COUNTROWS(DiagnosisTable),FIRSTNONBLANK(DiagnosisTable[Diagnosis],1))>0,1)
But this approach would require you to revise all the measures you wish to appear on your output summary. If it's just the total number of visits and the sum of the length of stay, that's not difficult, but if you need to revise all 50 measures it's a bit less appealing.
Here are the new measures for the number of visits and the length of stay which I have shown in a separate PivotTable on the same sheet:
[Cases]:=SUMX('Visits',[Diag Flag])
[LengthSum]:=SUMX('Visits',Visits[Length of Stay]*[Diag Flag])
And the output:
NOTE: My slicer is connected to both tables.

How to aggregate details in Pentaho Report Designer (PRD) 3.9?

Very new to Pentaho Reporting,
I have a query grabbing columns categories, quantity, and gross. It returns about 200 rows.
Without changing the query, is there a way for the report to display the aggregates for each category (I have category as a group)? For example, All you can eat should only display a sum of the Amount and GrossValue columns.
Same for dessert (notice there are two group headers - why?)
You just need to get used to with pentaho report designer.
Refer information given at the end of this page simple report.
You can add one parameter in group footer and set its properties.
They provides properties like aggregation-type, which can be set as Sum or count and then it will show at the end of each group with sum or count of the rows as per the type you specified.

Calculate total number of items received when item is received on more than one shipment

I have a set of tables in Access 2007 that I need to get to display the total number of items received. We order items against a job using the job number as a common reference (like an ID).
Each job has multiple items required. Most items have multiple shipments we receive. Each shipment is given a unique receiving ticket number, so they need to be entered individually and totaled.
I have:
tblJobItems :JobNumber, Item, QtyNeeded
tblReceived :JobNumber, Item, QtyRecvd, RTNumber (RT = Receiving Ticket)
tblJobs : JobNumber, JobQty (and more, but not relevant to this issue)
(JobQty is not always the same as the item's QtyNeeded. The job is like a run of a certain model of computer, the job qty is how many of that model. Items are sometimes 1:1, like a case or power supply, but can be 2:1 or 3:1 like having multiple hard drives.)
I have a query that works fine to show the number of items placed on order, but we want to expand it (or combine with other queries) to show the total number of items received per the job number on the same line. Eventually I'll use this number to change the status and other functions.
SELECT tblJobItems.JobNumber, tblJobItems.Item, tblJobItems.QTYNeeded, tblJobItems.PartStatus, First(tblJobs.BDT) AS FirstOfBDT, First(DateAdd("ww",-2,[BDT])) AS DueBy
FROM tblJobItems INNER JOIN tblJobs ON tblJobItems.JobNumber = tblJobs.JobNumber
GROUP BY tblJobItems.JobNumber, tblJobItems.Item, tblJobItems.QTYNeeded, tblJobItems.PartStatus;
This shows me in a listbox the items ordered and how many, the JobNumber is stored as ([Tempvars]![JobNum]), and the listbox only shows the records that match the JubNumber. (the tempvar is global, so it can be used in a query if that helps anyone)
I'm not opposed to having this go through two or three queries to get to the answer.
It turns out that the key piece needed in my query's SQL was:
Sum(tblReceived.ReceivedQTY) AS SumOfReceivedQTY, IIf(IsNull([SumofReceivedQTY]),0,[SumofReceivedQTY]) AS RECQTY
This sums up the quantity and also creates a new column in the query with the totals.