how do i subtotal on groups based on a condition - crystal-reports

My report is grouped on clinic, staffname with subtotals by clinic. I need to count patients by staff where they had more than 1 admit date. I can get the correct grand total, but on the detail and subtotals, it is a progressive number.
Here's what I want
clinic1
staffname1 10
staffname2 95
subtotal 105
clinic2
staffname3 6
subtotal 6
grand total 111
Here is what I get:
clinic1
staffname1 10
staffname2 105
subtotal 105
clinic2
staffname3 111
subtotal 111
grand total 111

A lot of this may depend on the structure of your data, e.g., what is in your "detail" level. I am also assuming that you want to count of how many patients had more than one admit date, not the total number of admits for patients with multiple admits. Given that, and assuming a patient will only appear once per admit date, then this should work:
Group by patient also, so it's clinic -> staff -> patient, but suppress that group.
Create a formula to count if the number of records in each patient group is more than 1, something like this: if count({patient},{patient}) > 1 then 1 else 0
Take the formula you just created, and use it to make a summary field wherever you want a total, e.g., in the staff head it will give you a count or that staff member, in clinic it will do so for clinic, etc.
Something else to consider: I'm guessing this could be intended to gauge staff on their quality by seeing how many patients had to seek additional treatment. Even if that's not the full intent, whatever this is being used for could be skewed by staff encountering more/fewer patients. For example, staff that have 10 readmits out of 100 visits would look worse than someone who only had 5 readmits, but had also only seen 20 patients.
So: Along with the metric on which you are requesting information, I would also add a ratio metric. In the staff header, this would be straightforward: count({patients}) / distinctcount({patients}) which will give you the ratio of distinct to repeat visits. Keep in mind also that this could skew high for a staff member that had, for example, 50 patients, but one of them came back a dozen times.

To get the count of the fields that has Greater than 1.
Assuming the count field is a database field and value coming directly from database
Create a formula #Count and write below code. Place the forumla in details.
:
if(databaswefield.count > 1)
then 1
else 0
Now take the summary of the #count formula in required group footers.
Let me know if you are looking for something different.
Edit..............................................................
If I got your comment correctly.
Though you take distinct count you can use that in your calculations by storing the value in a shared variable. Something like below and you can retrive value from that variable
Shared Numbervar count;
count:=distinctcount(patientid)

Related

Crystal Reports SUM formula help. Don't SUM values with specific IDs

I have a table with rows of Invoice data and I want to SUM the values of all line items where the Item ID is not equal to 0000 or 9999.
The Item IDs I want to exlcude 0000 and 9999 never change.
ITEM ID
NAME
WORK VALUE
TOTAL COMPLETED
0000
HOLD 1
0.00
1,234
1234
MATERIAL A
333.00
76.00
1235
MATERIAL B
567.00
7043.00
1236
MATERIAL C
981.00
321.00
1237
MATERIAL 4
430.00
5445.00
1238
MATERIAL 5
10.00
897.00
1239
MATERIAL 6
18.00
654.00
1240
MATERIAL 7
882.00
3.00
1241
MATERIAL 8
777.00
65.00
9999
ZY HOLD
0.00
111.00
So the value returned in the report from the example above should = 18,502.00 not 20,847.00
I have tried:
IF NOT((TONUMBER({Invoices.InvoiceItems~ItemNumber}) = 9999))
THEN
(SUM({Invoices.InvoiceItems~InvoiceValue})+SUM({Invoices.InvoiceItems~TotalCompleted}
but this doesn't work, it still sums the value from the 9999 line item
I would create a Running Total Field to accomplish this.
A Running Total Field works very similar to the Summary Field, but allows a lot more control over which records are evaluated when summarizing the data. To setup a Running Total Field for your needs try the following steps.
Create a new Running Total Field.
Set the "Field to summarize" to use the Total Completed column from your database. Set the "Type of summary" to SUM.
Set the radio button in the "Evaluate" section to "Use a formula", then click the X-2 button to create the formula that will determine if a row of data should be included in the sum or not. Whatever formula you enter here will need to return a boolean value. When this value is TRUE, the row's data is included, and when it's FALSE the row's data will be excluded. I would use the following formula here: TONUMBER({Invoices.InvoiceItems~ItemNumber}) <> 9999 AND TONUMBER({Invoices.InvoiceItems~ItemNumber}) <> 0000
The last thing to do is the setup the Reset conditions for the Running Total Field. This would be used if you were grouping data in some fashion such as by Customer and would allow you to sum the data for a single customer, then reset to zero for the next customer. If you are not using any grouping you can probably just leave this set to "Never".
Click OK to finish. :)
At this point all you need to do is drop the Running Total Field you just created into your report. Be mindful about which sections you place this field within though. If you place it in a header section, you will likely find it doesn't add in the last record in your dataset because the report hasn't printed it to the details section yet. I recommend placing Running Total Fields in Footer sections to avoid this nuance.
I hope this helps! And if you do have some grouping levels that you need help with setting the reset conditions just let me know what the grouping levels are for your report and I can update this answer for you.
You can create a new formula similar to yours:
IF TONUMBER({Invoices.InvoiceItems~ItemNumber}) <> 9999
AND TONUMBER({Invoices.InvoiceItems~ItemNumber}) <> 0
THEN {Invoices.InvoiceItems~TOTALCOMPLETED}
ELSE 0
and then just sum this formula field up.

Perform calculation on a different number of rows for each ID

Hopefully someone smart here can help me with a description how to solve this issue. I am relative new to SPSS and want to select cases with a certain requirement.
I have a group of Identeties who has made a mathtest multiple of times. We have 1000 ID where each person (ID) has done the test 10 times. Now i wanna select how many of these persons have scored atleast 40/50 once in this test. I have managed to do so.
Here is the problem. I now wanna calculate the average score of all the tests every individual has done after the first time they scored atleast 40 points.
Example: ID nr 8 has a score of; 34,35,27,37,32,45,41,32,34,47
These are all in 10 different rows. So ID nr 1 appears in 10 different rows. ID 2 in 10 other rows and so on.
Like this:
ID 1 Score 34
ID 1 Score 35
ID 1 Score 27
As you can see the person has scored atleast 40p at the 6th time. And i wanna take the average henceforth from this point. So in this case (45+41+32+34+47)/6.
I also wanna know how if i consider a person "smart" or not. A smart person is someone with atleast 2 mathscores with 40p+ (dosent have to be after each other, 2 seperate occations is ok)
How do i do that?
In the following code I assume you have a variable that identifies the order of the tests for each ID:
sort cases by ID TestNumber.
compute ScoreOver40 = score >= 40. /* this identifies all scores g/e 40.
compute seq=ScoreOver40.
* if seq was 1, all following seq values for same ID will also become 1.
if ID = lag(ID) and lag(seq)=1 seq=1.
if seq=1 scoresAfterFirst40 = score.
*now to aggregate by ID.
dataset declare agg.
aggregate /out=agg /break=ID /meanAfterFirst40=mean(scoresAfterFirst40)
/NumScores40P = sum(ScoreOver40).
In the new dataset called agg you should find for every ID the mean of scores after the first score of 40 or more, and the count of scores of 40 or more in all the 10 tests.
EDIT:
Now you can use the aggregated data for further analysis. For example, you can determine which IDs had two or more high (40+) scores:
dataset activate agg.
compute GoodAtMaths = (NumScores40P >= 2).
exe.

Tableau - Related Data Source Filter

I have data split between two different tables, at different levels of detail. The first table has transaction data that, in the fomrat:
category item spend
a 1 10
a 2 5
a 3 10
b 1 15
b 2 10
The second table is a budget by category in the format
category limit
a 40
b 30
I want to show three BANs, Total Spend, Total Limit, and Total Limit - Spend, and be able to filter by category across the related data source (transaction is related to budget table by category). However, I can't seem to get the filter / relationship right. That is, if I use category as a filter from the transaction table and set it to filter all using related data source, it doesn't filter the Total Limit amount. Using 2018.1, fyi.
Although you have data split across 2 tables they can be joined using the category field and available as a single data source. You would be then be able to use category as a quick filter.

Crystal Reports 2013: Filter shown records

I have a report with the following structure:
<sales person>
<appointment date>
<appointment status>
Now, the appointment status can be either 'kept', 'cancelled by customer', or 'cancelled by sales person' (for simplicity). I want to calculate the percentage that were cancelled. To calculate that, I will need to select all of the appointments, and divide the number that was not kept by the total number. Okay, I get that.
Now, the trouble is that I also want to show the appointments that were cancelled in my report, and exclude the appointments that were kept. In other words, I pretty much just want to skip printing these irrelevant records. How can I accomplish this?
formula1
If {<appointment status>} = "kept" then 1 else 0
That will give you a count which you can use to get your percentage for sales person.
if sum({#formula1},{<sales person>}) > 0
then sum({#formula1},{<sales person>}) % count({<appointment status>} ,{<sales person>})
else 0
Then suppress the details with a formula like this
{#formula1} = 1

Summarizing each subgroup in Group Footer - Crystal Reports

I'm trying to work on a report for a client. Basically I need something like such
Group 1: Customer ID
Group 2: Truck ID
CustID Vehicle ID Detention Time
------ ---------- --------------
ABX 100 60
35
20
TOTAL: 115
200 80
15
TOTAL: 95
300 10
TOTAL: 10
TOTALS FOR CUSTOMER ABX
100 115
200 95
300 10
Is there anyway to accomplish this without a subreport? I was hoping for a "summary field" that I could summarize more than just a single value.
Thanks!
(FYI using Crystal Reports 2008)
Use a crosstab; place it in the report-footer section.
There might be a better way to do this, but the one that comes to mind is to use two arrays: One to store the truck ID and another to store the corresponding total. In each inner grouping (TruckID), just tack on another array element and store its total time. To display, you could cast the values to strings, attach a newline character after each entry, and set the field to "Can Grow". So altogether, you'd need three formulas: one to initialize the arrays (in GH1), one to update the arrays with sum({truck.time},{truck.ID}) (in GF2), and one to display each entry (in GF1).
With that being said, CR has terrible support for containers... You're limited to 1-dimensional, non-dynamic arrays that are gimped at 1000 items max. It doesn't sound like these would be big problems for what you're trying to do, but you will need to redim preserve the arrays unless you know ahead of time how many trucks you'll have per customer.