12 Replies Latest reply on Sep 27, 2016 6:21 AM by Bayapa Reddy

# How to Create date Field?

For example,

i have Data source which has "Year" and "Month" fields.

i need to create Date field by using them.

How can i do that.

Thanks & Regards,

Pavan Kumar

• ###### 1. Re: How to Create date Field?

Hi Pavan,

Please create a Calculated Field with the below Formula. Assuming your data has month and Year as numbers.

DATE(str([Month])+"/1/"+str([Year]))

1 of 1 people found this helpful
• ###### 2. Re: How to Create date Field?

PFB Screenshots.

• ###### 3. Re: How to Create date Field?

I have created a Calculated Field with your formula but when i place it in View.it is showing Null values.

here i am attaching sample workbook with dummy data,can u plz check it

thanks&Regards,

pavan Kumar

• ###### 4. Re: How to Create date Field?

Pavan, how are your date fields?

Numbers, texts?

It would be something like this:

MAKEDATE(Year([Running Date]), Month([Running Date]),1 )

I created two pieces of data in number format, but since you have Year and month you can use them directly.

Post a piece of data. I can't open your twbx. I don't have your Tableau version.

• ###### 5. Re: How to Create date Field?

i am posting screenshot of Dummy data

This is how my Data looks like

• ###### 6. Re: How to Create date Field?

Hi Pawan,

Please use this formula for your data. Your month is in String , hence converting it to integer.

DATE(str(

If [Month] = "january" then

1

ELSEIF [Month] = "february" then

2

ELSEIF [Month] = "march" then

3

ELSEIF [Month] = "april" then

4

ELSEIF [Month] = "may" then

5

ELSEIF [Month] = "june" then

6

ELSEIF [Month] = "july" then

7

ELSEIF [Month] = "august" then

8

ELSEIF [Month] = "september" then

9

ELSEIF [Month] = "october" then

10

ELSEIF [Month] = "november" then

11

ELSEIF [Month] = "december" then

12

end

)+"/1/"+str([Year]))

1 of 2 people found this helpful
• ###### 7. Re: How to Create date Field?

Hi.

Use Dateparse function:

DATEPARSE("dd.MMMM.yyyy","15.Abril.2015")

My month is in portuguese but works the same way.

I created a calculation to union fields(Cálculo1):

"01." + [Month] + '.' + str([Year])

and then create another converting:

DATEPARSE("dd.MMMM.yyyy",[Cálculo1])

2 of 2 people found this helpful
• ###### 8. Re: How to Create date Field?

Hi Pawan,

Yes, Luciano's method is fine too. You could either use the below or the previous one I shared.

Formula for your calculated field will be

DATEPARSE("dd.MMMM.yyyy","1."+[Month]+"."+str([Year]))

• ###### 9. Re: How to Create date Field?

Rajiv, this formula does not work.

First part is day. as you declared "dd. it has to be "01".

Second part: i don't know why but dataparse does not understand very well this concatenation.

Once i created a previous calculation it worked.

• ###### 10. Re: How to Create date Field?

Thanks Luciano. I tried with 1 and it worked But having it as 01 is a good one too

• ###### 11. Re: How to Create date Field?

Depending on your data source DATEPARSE() and/or MAKEDATE() function(s) can be used to create a date. Under Date Functions in the online manual you can find these descriptions:

Note that MAKEDATE() uses numbers instead of strings, so it will be much more performant.

--Shawn

2 of 2 people found this helpful
• ###### 12. Re: How to Create date Field?

Hi ,

DATEPARSE
Function,
This function is only available for Microsoft Excel,
MySQL, Oracle, PostgreSQL, Tableau data extract and text file data sources.