Return 0 value if Details duplicated - crystal-reports

I need your help in creating crystal report.
I have a formula in details section that computes working time.
How do I make the value return 0 if it is duplicated?
Here's the scenario
Name Time (Hours:Minutes)
John 1:20
........ 3:30
........ 3:30
Total Hours -> ?
My problem is I dont want to use the duplicated values (3:30) like shown above. I want a total hours for 4:50.

you have two options:
check the option in Database tab.. Select Distinct Records so that duplicate records will be eliminated.
If you don't want to use the first option then to calculate use Running Total so that you sum only those that are distinct...
Create running total something like Do sum only after change of time value

You can use the function "previous" to compare the current value with the previous value, but it works only with fields.
But i am not sure if i understood, you may be more precise about your question.
1) make a formula called "hours" or some other name
if not isnull(previous({Result.Time}) and {Result.Time} = previous({Result.Time}
then 0
else {Result.Time} /* you have to assure the same return type */
2) let the "total hours" be a sum of the formula "hours"
Note that it will work only if the rows are ordered by hours.
The result is the same of using a running total fields as purposed by Siva.

Related

How to get the COUNT of rows in Crystal Report

I have a data in database which gives me 8 rows based on date range out of which 5 are HCT, is there any formula in crystal report where I can get that count of those 'Abbr' ?
I am comparing HCT text from Dynamic report selection, I need to know can we create a variable which gives us count of 'Abbr'.
like for
HCT should return 5
US should return 2
RN should return 1 value.
UPDATE 1:
Here is what I am trying to do. I have secondary selection criteria as Dynamic report along with date range.
in the above example I have selected only "HCT", now even though sql data is returning 8 rows (HCT,US,RN) I need only the HCT count i.e. 5.
If I select "HCT" and "US" in the secondary criteria then I should get count of both HCT and US i.e. 5 + 2 = 7.
if I am not selecting anything then it should return 0, so irrespective of the data from DB, the value should be summed based on selection of my criteria.
am I clear enough?
Use Running Totals.
Specifically, make a Distinct Count running total for each Date Range code. You can set a formula in the Running Total Wizard to only evaluate records where, for example, {DateRange} = "HCT"
I found the solution for my question, I am just putting it here so that someone may help for the above mentioned formula.
This is what I did
Created a Formula(not running totals) by name SumOfSkills
if({Command.GlobalSkillAbbr} in {?GlobalSkill}) then 1 else 0
here Command.GlobalSkillAbbr is my "HCT" and '{?GlobalSkill} will contain all Global skills.
and used another formuala to sum it up.
Sum(SumOfSkills)
which gives me desired output.

Using running totals in formulas - Crystal reports

I have created a set of running totals looking for specific fields in a database.
If these fields are located, a subsequent sum is performed to calculate the total for that field. e.g. Field to Summarise - DB.Field.Value-Sum. Evaluate - Use a Formula-Field Name ='1'
This sums the totals for this field. The issue is that I have many running totals doing this, and what I want to do is add these together to provide a total for all of these. Currently I have a formula that uses each field with a '+' between each. This appeared to work fine, but when tested against a record where some of these fields are blank, the subsequent formula displays nothing.
Any advise on what I should do here/ am doing wrong?
Thanks
It sounds like a null record (empty value) is breaking your running total. You have a few options
Use a formula to check for, and replace a null value with another value (Zero, for example) and then use that formula in your running total calculation
if isnull({Command.Decimal}) then 0 else {Command.Decimal}
Use a SQL expression to replace null with another value Isnull(Tablename.Columnname,0) - use this in your running total
On the running total, under "evaluate" select Use a formula and use this formula not(isnull({tablename.columnname})) -- If the record IS null, the running total does not evaluate it. It will be ignored by the running total.

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

Displaying only the last of a sequence in Crystal Reports

I have a report that will occasionally have more than one detail record in a group. In such a case I only want to display the last in the sequence. I have a sequence number associated with each record so I need to suppress all detail rows in the group other than the one with the maximum sequence number.
I've tried using a global variable to recalculate the max value as of each detail record but I haven't been able to write a formula that, while printing, can use this maximum sequence number to suppress the row if it does not contain a value equal to the max sequence number.
From what i understand you have data organized by this:
Data1 Data2 SeQuencenumber
1 a 1
2 b 1
2 c 2
2 d 3
And from what i understand your want your output look like (group by Data1):
Data1 Data2 SeQuencenumber
1 a 1
2 d 3
To do so you need to write formula in detail section which compares your current detail sequence number and count of all for that group (Data1). Right-click your detail section and write formula here
Formula looks like :
if {SequenceNumber} = count ({SequenceNumber},{Data1}) then true
else false
Hope it helps, if you have any further questions feel free to ask.
try like this:
Shared Stringvar array concatenate;
concatenate:=concatenate+CStr(Sequencenumber);
now in suppress condition of details:
Shared Stringvar array concatenate;
if Maximum(concatenate)=Sequencenumber
Then false
else true
I had tried a solution similar to the one from KuKeC but with the maximum function instead of count. But while reviewing the KuKeC solution I finally saw that I was already suppressing the detail band when a date in the detail did not match a parameter date, yet the maximum function was giving the max of all data whether displayed or not.
So I first needed to add a formula field that would return the sequence number only if the data date matched the parameter date
if {PSLRegister.PSLRPPStartDate} = {?PP_Start_Date} then
{PSLRegister.PSLRSeqNo}
else
0
then I used this formula field in the equation to suppress the detail record
Maximum({#SeqIfDateMatch}, {TrnsltEmployee.TSEmployeeID}) <> {PSLRegister.PSLRSeqNo}
Thanks to all

How to calculate current-1 year in tableau

I am using Tableau 8.2,I want to show calculations for current as well as previous year,how to apply this dynamically? it is getting possible if the year is written manually but it will be only temporary solution, how to do that dynamically?
i.e on applying filter Year=2013 then sales and orders value of current-1 year should be displayed
I have sales and orders On the Columns.
A quick solution to this would be to create a new calculated field for previous year sales by using the Lookup function.
For example:
LOOKUP(SUM([SALES]),-1)
You can simply introduce two calculated fields which will give you the current and previous year. These can be used on the rows and columns shelves or any where else depending on whether your aiming for chart, text table or any other viz.
Calculated field 1 = Current Filter
if datediff('year',[Date],TODAY() )=0 then 1
ELSE 0
END
Calculated field 2 = Previous Filter
if datediff('year',[Date],TODAY() )=1 then 1
ELSE 0
END
The formulas above can be used if the required measure is just a count otherwise you could replace: then 1 with then [Amount] or whatever measure this applies to.
Create a parameter and use IF Year = 'Parameter Value'THEN Sales ELSE 0 END
or use LOD to know the Max Year if you want it to be more dynamic: IF Year = {FIXED: MAX([Year])} THEN Sales ELSE 0 END