Calculate rate in Crystal Report - crystal-reports

I need to calculate the rate of infection per patient from a report. This report returns the number of months the patient had a catheter and the number of infections they had during this time.
What i need to do is add a column at the end that displays the infection rate per patient. For example, if a patient has had a catheter in for 12 month and they have had 2 infections, the rate is 2:12 or 1:6.
How do i create this in Crystal Reports? Not used it much so learning.
Cheers,
Mike D
Edit: The data is from a MySQL database that holds all patient information. I extracted the date that the catheter was inserted as well as the date it was removed and the nunber of infections the patient had during this time. I then used MySQL to calculate the number of months it was in from those two fields.
No I need to calculate (with MySQL or Crystal) the rate of infection per month.
For example, a patient has a catheter for 12 months and has 2 infections, the rate is 2:12 or 1:6.
I hope this is clearer.

It will be a bit complex report.
First group by patient that will be group 1
Group 2 will be date
Detail part will be list of infections for that patient as recorded in database
You can take the count of dates that is group2 count and count of infections and display in group 1 as required...you can manipulate in the format you need.
If you dont need then you can just display group 1 and supress group2 and details.
Let me know after trying this.

Concordinate your data from the database and try formula in cyrstal reports or try doing all the back end calculative steps in SQl and just use the reports to show those data sets. its far more easy to do those things in SQL than Crystal Reports.
-Sid

Related

How to display month and YTD data on same group band in Crystal Reports

I am working on a productivity report. I need it to display units for the month along with YTD units.
Example:
Month units YTD Units
Staff (group 1)
Accounting Period (group 2)
Service Category (group 2)
Detail - services with minutes that are calculated into minutes. This may or may not be hidden.
Service Category (footer) Units sum for period Total Units sum
Page Break
Accounting period.... and so on until we run out of accounting periods for that staff with services, then onto the next staff.
Units are being calculated in a formula field based off of minutes of the service. How can I accurately display the year to date units? Everything I've tried hasn't worked. Perhaps I'm doing a running total wrong but it told me I couldn't use a formula field in it (units). I hope my explanation makes sense.

Tableau Summing up aggregated data with FIXED

Data granularity is per customer, per invoice date, per product type.
Generally the idea is simple:
We have a moving average calculation of the volume per week. MA based on last 12 weeks (MA Volume):
window_sum(sum([Volume]),-11,0)/window_count(count([Volume]), -11,0)
We need to see the deviation of the current week vs the MA for that week (Vol DIFF):
SUM([Volume])-[MA Calc]
We need to sum up the deviations for a fixed period of time (Year/Month)
Basically this should show us whether on average, for a given period of time, we deviate positively or negatively vs the base.
enter image description here
Unfortunately I get errors like:
"Argument to SUM (an aggregate function) is already an aggregation, and cannot be further aggregated."
Or
"Level of detail expressions cannot contain table calculations or the ATTR function"
Any ideas how I can go around this one?
Managed to solve this one. Needed to add months to the view and then just WINDOW_SUM(Vol_DIFF).
Simple as that!

Creating a calculated field with ratio of number of complaints to population in Tableau?

Count of complaints per State by Year
I have the count of complaints per state by year in the first picture. I have another dataset which has the population of each state by year. How do I account for population and present only the ratios of count of complaints to population?
Snapshot of first dataset
Snapshot of second dataset
My thought was to create a calculated field to create a ratio but I'm having trouble with adding up the number of complaint counts within a certain year and then dividing by population year. How do I write the formula that only counts complaints within 2011, 2012, etc and dividing it by that population year?
Let me know if there's an easier way to do it as well, thanks for your time.
Edit 1:
Second dataset Pivoted
Population & Complaint Count
I've pivoted my second dataset and now I'm trying to graph both the counts of population and complaints. The population count across the years increases but the count of complaints stay exactly the same; its the sum of all complaints for that particular state for all the years.
Also, when I graph population count with 'Date Received' from the first dataset, I get the total population count across all the years instead of that particular year, like so:
Population per year
How do I properly 'blend' in the two date variables so that it works with both population count and complaint counts in both datasets?
Edits 2:
Blended Year
I changed the [Years] datatype in data source 2 into a date to match the date type of [Date Received] in data source 1. I also took only the 'year' parts because it would only count things on 1/1 of each year if I used [Years] in data source 2.
Now the graphs look similar except when I'm using [Years] instead of [Date Received], all the values are about several thousand off. I tried adding another relationship except this time for month again and then it only counted values for that month.
How do I account for the discrepancy and make [Years] work just like [Date Received] ?
Reshape data source 2, following these instructions.
Then you'll be able to blend the 2 data sources on State and Month and Year.

Aggregating data from the US stock market in Tableau, using different time frames

I am a very basic user of tableau and I have not found an answer to my question.
I have a txt file that has historical daily data for 98% of all the stocks in the US, with their daily capitalization. Each stocks has its TICKER, Daily Market Value for every trading day of the year, and its SECTOR.
I did a simple time series that display SUM([Mktval]) (sum of all individual market values) across all stocks, on a daily daily, and where I can see that the total value as of 2016 is about 24 Trillion USD, as in the image below.
When I change the view column from DAY to YEAR, I don't see the right values, but something a lot larger. So I realized that I need to do SUM([Mktval])/252 to get the right value for a year (there are 252 trading days in a year).
If I change the view to MONTH, as in the chart below, the numbers are again wrong because 252 is not the right value to use in the division.
Is there any way that Tableau can adjust the values automatically to reflect the AVG MktVal across different time intervals?
Thanks
Replace SUM(Mktval) on the Rows shelf with the following calculated field
avg({ fixed day(Date1) : sum(Mktval) })
That solution is all in one step. It is perhaps a bit more clear to use 2 steps. First, create a calculated field called total_daily_market_value defined as
{ fixed day(Date1) : sum(Mktval) }
Then make sure that calculated field is a measure. It is an LOD calculation that you can think of as a separate table with one value for each day showing the total market value for that day.
Drag that measure to a shelf, and then change the aggregation function to AVG(), MEDIAN(), MIN(), MAX() or STDEV() as desired. Tableau will aggregate the total_daily_market_value using your chosen aggregation function for whatever values of Date1 are in your view.

Calculate the Average of multiple Averages

I need to calculate the average of multiple averages within Crystal Reports with specific criteria. My report averages scores for multiple courses by a developer. I need to get the average value of the averages, based on the number of courses for that developer:
Course 1 10 responses Course 1 Average 42.86
Course 2 12 responses Course 2 Average 39.36
How do I create a formula that give me the correct Average ((42.86 + 39.36)/2) of those two courses for that developer?
Try a Running Total for that field, where the Type of Summary is set to "Average". Specify that the total should reset every time it reaches a new Developer group.
Sometimes Crystal won't let you summarize a summary. If it gives you guff, you can achieve the same effect with Shared Variables. Simply add each average in turn to the shared variable, then divide by a distinct count of averages. The final Formula field would look something like:
Shared NumberVar sum;
Shared NumberVar count;
sum/count