4 Replies Latest reply on Dec 20, 2018 8:25 AM by Jim Dehner

# Numeric conversion to Number & Text

Hi fellow Tableau users, I was hoping to get some assistance on this one field....I'm sure it's been tossed around in the forums before but I just couldn't find it.

Below is a sample of my problem and I'm wondering if anyone has a solution.

Orignial data:

Years of Service: 22.5

Would love a CF to convert this to

Years of Service: 22 years 6 months

Any ideas?!?

Thanks,

david

• ###### 1. Re: Numeric conversion to Number & Text

Hi David

Try this

left(

STR([number 22.5]),2)  +' Years '

+ str( round(([number 22.5]-floor([number 22.5]))*12,0)) +' Months'

where Number 22.5 is the years of service -

Jim

If this posts assists in resolving the question, please mark it helpful or as the 'correct answer' if it resolves the question. This will help other users find the same answer/resolution.  Thank you.

• ###### 2. Re: Numeric conversion to Number & Text

Perfect! This worked just the way I was wanting it too.

Thanks for the help Jim!

Final CF: left(STR([Years of Service]),2)  +' Years '+ str( round(([Years of Service]-floor([Years of Service]))*12,0)) +' Months'

Cheers,

david

• ###### 3. Re: Numeric conversion to Number & Text

Hey Jim,

Follow up question, for years of service under 1 year (i.e. 0.67 years) when I run the calc it gives my 0 years and 8 months, which is correct; but is there a TRIM function that I could put in the calc to trim out the 0 years part and only return the 8 months part?

thanks again for all your help!

cheers,

david

• ###### 4. Re: Numeric conversion to Number & Text

These are the functions available for strings and yes Trim() is in there

Jim

If this posts assists in resolving the question, please mark it helpful or as the 'correct answer' if it resolves the question. This will help other users find the same answer/resolution.  Thank you.