how do you change the data type of one cell in a colomn on crystal report

on my crystal report, one row of the imported fields need to different data type than the rest of the cells in the colomn. How do you do that?
jchangmwmcAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
I would add 2 cells for the same column  (one for each format) and use the Suppress property to set a condition for when to suppress it.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mlmccCommented:
That would work.

You could also use a formula like this.  If you wanted say the 10th record to use a text field instead of a number field

If RecordNumber = 10 then
    {YourTextField}
Else
   CStr({YourNumberField})

mlmcc
Ido MilletProfessor of MIS at Penn State Erie and Owner, Millet SoftwareCommented:
Place the field on the report canvas,
Right-click, Format Field, Common Tab
Enter an expression for the 'Display String' property, such as:
IF NumericText({file.REFERENCE}) Then
     ToNumber({file.REFERENCE})
Else
     0;
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

jchangmwmcAuthor Commented:
Thank you all for your quick responses. Let me add a little details: what I am trying to do is
I imported an excel file into crystal report. everything went well except that one row of each column has different data type than the rest of the documents. It has to be date data type rather than number data type in order to show correct info on the report. It should look like this:

Jan-12         Jan-13        Jan-14      Jan-15      Jan-16
123                456             456          786           555

right now the dates row shows as a number:  42156 which is the crystal conversion of the month and year into a number.

I appreciate all your help, but feels easier to try mlmcc's and idomillet's. will update the result
Ido MilletProfessor of MIS at Penn State Erie and Owner, Millet SoftwareCommented:
A date in Excel is actually a number disguised as date.  
It is the number of days since January 1, 1900

You can reverse that logic in Crystal using a formula such as:
DateAdd('d', {your_excel_date_column}, #1/1/1900#)  

For example, DateAdd('d', 42017, #1/1/1900#) returns January 15, 2015

You can test to see if a value is a Date using the IsDate() formula.
jchangmwmcAuthor Commented:
i tried to use both mlmcc's and idomillet's methods, but didn't work. Would you please be more specific on how to set first row of each column as date data type and rest of the the columns as numeric data type?

thanks!
Éric MoreauSenior .Net ConsultantCommented:
mlmcc already gave you the solution for that:

If RecordNumber = 1 then
    {YourTextField}
Else
   CStr({YourNumberField})

Open in new window

mlmccCommented:
If you need a date as first row then numbers after that
Eric's formula needs a minor change.  You need to convert both to strings

If RecordNumber = 1 then
    CStr({YourField},"dd-MMM-yyyy")
Else
   CStr({YourField})

Open in new window


Add that formula to the report then put it where you want the data displayed.

mlmcc
James0628Commented:
Do you need to use that date as a date value (eg. to compare it with another date), or do you just want to show the date on the report?  Similarly, do you need to use the number as a number (eg. to calculate a total), or do you just want to show it on the report?

 If you just want to show that value (date or number) on the report, you can use a formula like the last one that mlmcc posted, but you need to convert the number to a date first, and then convert that date to a string.  Combining mlmcc's and Ido's suggestions:

If RecordNumber = 1 then
  CStr (DateAdd ('d', {your field}, #1/1/1900#), "MMM-dd")
Else
  CStr ({your field})

 You can change the CStr arguments to change the date or number format.


 Assuming that Ido was correct about how to convert the Excel number to a date, a slight variation on that would be:

If RecordNumber = 1 then
  CStr (Date({your field} + 2), "MMM-dd")
Else
  CStr ({your field})

 The CR Date function will convert a number to a date, but for some reason it uses the number of days since 12/30/1899, instead of 01/01/1900, so you need to add 2 days.

 As Ido mentioned, if there's any doubt about the numbers giving you valid dates, you can use the IsDate function to test them first, to avoid getting an error.

 James
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.