Dolphine
Dolphine

Reputation: 1

How to convert days(ex: Monday, Tuesday, etc) in string data type to day type in Tableau?

I have a column("Day of week") which shows days of week data such as "Monday", "Tuesday", "Wednesday", etc. When I load it into Tableau, it always shows as string data type. I need to convert it to day data type under Datetype in order to do time series modeling. However, when I tried DATEPARSE function below to try converting string to date format, it kept failing.

DATEPARSE('MMM',[Day of Week]) DATEPARSE('EE,EEEE',[Day of Week])

can anyone help, please? Did I miss anything here?

Upvotes: 0

Views: 96

Answers (1)

reusen
reusen

Reputation: 511

To create a date from constituent integers, use MAKEDATE.

With: Y,M,D as 2020,8,25

the date is created as MAKEDATE([Y],[M],[D])

The string day is insufficient for the date calculation because there are several e,g, Mondays each month. You need the day of the month.

That said, if you do want to convert the string day to an integer, it can be done using CASE, as follows, where day is the string day:

CASE [Day] WHEN 'Sunday' THEN INT(1) WHEN 'Monday' THEN INT(2) WHEN 'Tuesday' THEN INT(3) WHEN 'Wednesday' THEN INT(4) WHEN 'Thursday' THEN INT(5) WHEN 'Friday' THEN INT(6) WHEN 'Saturday' THEN INT(7) END

Upvotes: 1

Related Questions