Search code examples
datetexttableau-apihana

How can I convert text format to date format Tableau?


I have a text format in tableau: yyyymm. I would like to convert this to a date format. I am using Tableau downloading data from SAP HANA. Thank you.


Solution

  • The dateparse() function is only available for certain types of database platforms. SAP Hana is not one of them.

    From the Tableau online documentation:

    Note: This function is available through the following connectors: non-legacy Excel and text file connections, Amazon EMR Hadoop Hive, Cloudera Hadoop, Google Sheets, Hortonworks Hadoop Hive, MapR Hadoop Hive, MySQL, Oracle, PostgreSQL, and Tableau extracts. Some formats may not be available for all connections.

    You have two options as workarounds.

    Option 1: Use a data extract. With an extract, you can use dateparse().

    Option 2 (if an extract is not possible): Use the date() function and parse out the string. Use string functions to grab the different date parts and pass them into the date() function.

    DATE (RIGHT([Original Date], 2) + "/" + "01" + "/" + LEFT([Original Date],4))
    

    Since your source data in the posted question only contains month and year, I assumed a day of the month to be 01.

    This workaround, plus a few other tips for your situation, are found in the Tableau help online at https://onlinehelp.tableau.com/current/pro/desktop/en-us/help.htm#data_dateparse.html.