How can I use DateDiff in a seperate Crystal Reports formula? - crystal-reports

I have a formula which uses DateDiff to find out the difference between two dates and excludes the weekends.
I'd like to then use that DateDiff in another formula to calculate averages based on and if/then criteria.
When I put average({date diff formula}) I receive an error of "Invalid Argument was encountered"
I can't use the date diff formula in any formula I try to use it in, is there a reason for this?

Example DateDiff formula:
DateDiff('d',*datecolumn*,today)
Then pass that thru into your running total, eg:
Make a grouping in your group expert for the set you wish to summarize with an average, select that group in the Evaluate section and, if desired, in the Reset as well.
Let me know if this isn't quite it for you, good luck!

Related

Find difference between two calculated groups?

I have dummy HR data, and I want to color format via a map the difference in median salary based on groupings of birth year.
I have a quick calc field to separate them into birth year groups:
IF DATE([Date of Birth]) >=#1976# THEN "Group 1"
ELSE "Group 2"
END
Now I want to find the difference between the median salaries for those two groups, but I want to conditionally format them via a map to see where the median salary remained similar or differed a lot.
For instance: Median(Group 1([salary])-Median(Group 2([salary]) would give me a +/- difference and then I'd like that to be colored via a gradient and then outlines via state level detail.
This is probably so easy, but I can't think of how to do it via those groups. Would this be a LOD calc?
Define a calc to return the salary for rows in group 1, and null otherwise. Call it say, Old_Folks_Salary, defined something like if Year([Birth Date]) < 1976 then [Salary] end (If the condition in the if statement is not satisfied, and there is no else clause, the expression returns null.) Define a similar field for the youngsters.
The trick to know is that aggregation functions, like Median, silently ignore null values. It’s as if the null values don’t even exist. So ... You can now express your aggregate calculation as
Median([Old Folks Salary]) - Median([Young Folks Salary])
For extra credit, you can replace the hard coded threshold of 1976 with a parameter, and look for more politically acceptable field names.

Use a Level of Detail Expression in Tablaeu on 1 of 2 forms of a date variable

In Tableau a Level of Detail Expression allows you to create a calculated variable that is affected by none or only some of the view level filters.
I have a view that has 2 filters based on the same column -- a YEAR(Date) filter and a MONTH(Date) filter.
If my Level of Detail Expression is:
{EXCLUDE [Date mdy]: SUM([count.Attrition])}
that won't work because it would remove both date filters. I only want to remove the MONTH date filter.
However, this
{EXCLUDE [MONTH(Date mdy)]: SUM([count.Attrition])}
is an invalid expression and this:
{EXCLUDE MONTH([Date mdy]): SUM([count.Attrition])}
is allegedly valid but doesn't actually work.
Hack-R, how about using FIXED, I think that should help solve this:
{FIXED [Year] : SUM([count.Attrition]) }
Using FIXED is basically forcing Tableau to calculate aggregate measure at specific level - in this case on Year
[Year] is just a simple calculated field which returns Year value.
YEAR([Date mdy])
Creating a dedicated calculated field is probably not really necessary in Tableau 10, but it's just my personal preference to keep things organized.
You might be wonder why EXCLUDE didn't work - I think the main use-case is different with INCLUDE/EXCLUDE and probably best explained in this (a bit lengthly) article.
Hope this helps.

average of particular filed in crystal reports

i have a crystal report i want to find average of cntEcode value
so i try to add new formula field AverageEcode then i try to give code like that.
Average{DriverPerformance.CntEcode}
.but while saving showing error:
There is an Error with this formula.
Do you want to save any way.
how i can calculate average of particular field using formula filed. I attached picture what i try to do..how i can find out average of this values,If any one know.please help me to find out.
My
just give like this: sum({DriverPerformance.CntEcode}) / count({DriverPerformance.CntEcode})..then We Will get exact average value
Use a running total field to create the average. This will also give you the ability to average, sum, max, min, etc. by group. It will also give you the ability to add filters (if needed)

iReport query results break-down by week or day

I have used iReport to create a simple JasperReport which I run on a JasperServer. It queries some fields from a number of MySQL tables based on their creation timestamp. I am providing the start and end timestamps of the period to cover in the report as parameters of type java.sql.Timestamp. This works fine.
I was asked to introduce the ability to show a break-down on weeks or days of the report data. I would like to get some ideas on where to start with this. At this point I don't think I can accommodate this 'break-down' in the report query, since this feature seems beyond what SQL is designed to do. I know this sounds like an OLAP drill through, but I would like to avoid OLAP if possible (steep learning curve, tight deadlines).
My first thought was to create a subreport for each week or day . But this would leave me with an arbitrary number of subreports (depending on the overall time period covered by the report, which varies at each execution), and as far as I can tell iReport does not support this.
Here is one way to break the report down.
Create another parameter, groupby, which holds the a value that designates the grouping requirement. The values can be numeric, string or whatever else as long as it corresponds to day, week, month, etc.. grouping available.
Create a report group, breakdown, which will provide the breakdown. The group expression will depend on the groupby parameter. The expression is the date on the record except any detail finer than groupby value will be trimmed.
Create a variable, total, that will sum the data in the records. The variable should be reset on breakdown group and can be printed in the breakdown trailer band.
Make sure the sql queries sortby the date so that the groupby expression works.
Let me know if you have questions.

Crystal reports: using summary field in formula / summing time field in formula

In crystal reports I want to show the sum value of time objects, i.e. An employee worked in one month three days and on each day a variable amount of hours.
Is there anyway to sum a time field?
Or as a workaround I could use the time field as an integer, sum this and display. But then I would like to change the display format by using a formula. I cant find a way to include summary fields in a formula...
Thanks in advance
PS I am using CR 2011 (just the program not through VB or anything).
You cannot sum a date/time field. You will have to use datediff("n",{datetime1},{datetime2}) to get a time interval between two date/time fields in minutes.
To use a summary function in a formula, you can use this sum({#YourMinutesFormula},{FieldYouAreGroupingOn})
You may omit the second parameter if you want the summation over the entire report instead of a grouping level. Check the Crystal Reports help file for more details on Sum().