添加链接
注册
登录
link之家
链接快照平台
输入网页链接,自动生成快照
标签化管理网页链接
相关文章推荐
深情的扁豆
·
奈学p7数据分析架构师保薪班课程笔记 - 掘金
·
1 年前
·
有情有义的黑框眼镜
·
SyncLock Statement - ...
·
1 年前
·
link之家
›
Type Conversion - Tableau
date
string
tableau
https://help.tableau.com/current/pro/desktop/en-us/functions_functions_typeconversion.htm
爱旅游的绿豆
1 年前
</noscript><div id="app" class="wrapper"><header id="tableau-help-article-header" class="container--full-width quick-help-header"><div class="container--centered"><div class="header__mobile-menu quick-help-hidden"><menu-tree-toggle/></div><div class="header__logo quick-help-hidden"><a href="https://www.tableau.com/en-us/"><img src="./Resources/tableau-logo.png" class="header__logo__img" alt="Tableau"/></a></div><div class="header__search"><search-header-help placeholder="Search"/></div></div></header><div class="container--navigation-top quick-help-hidden content-only-hidden"><div id="help-subheader" class="subheader print-hidden"><div class="container--centered"><h4 class="heading--subheader">Tableau Desktop and Web Authoring Help</h4></div></div><div class="container--top-links"><div class="container--centered container--breadcrumbs"><div><breadcrumb-links-help/></div></div><div id="help-container-menu-headings" class="container--menu-headings"><nav class="nav-medium-screen"><menu-heading-links-static-help menu-title="In this article" :disabled="false" :headings="pageHeadings"/></nav></div></div></div><div class="section--main container--full-width"><div class="container--centered"><nav class="nav-side nav-side--left" role="navigation"><menu-tree-help menu-title="Contents"/></nav><article role="main"><h1 id="contentH1">Type Conversion</h1><div class="caption article__tags content-only-hidden quick-help-hidden"><span class="article__tags--applies-to">Applies to: Tableau Cloud, Tableau Desktop, Tableau Public, Tableau Server</span><br/><span class="article__tags--role"> </span></div><div id="content-body"> <p>This article introduces type conversion functions and their uses in Tableau. It also demonstrates how to create a type conversion calculation using an example. </p> <h2 is="heading-item" :level="2" id="why-use-type-conversion-functions"><a name="Why"/>Why use type conversion functions</h2> <p>Type conversion functions allow you to convert fields from one data type to another (this is called "casting"). For example, if you have date information in a field with a string data type, you won't be able to use that field in date calculations unless the field is cast (changed) to a date data type. </p> <p>For example, to use a string date field in a DATEDIFF function, you'd also need to use a date type conversion:</p> <p><code>DATEDIFF('day', [Date Field], DATE([String Date Field]) )</code> <p>Without the DATE function changing the data type, you'd get an error that "DATEDIFF is being called with (string, date, string)". </p> <p class="note--tip"><b>Tip</b>: Fields have default <a href="datafields_typesandroles_datatypes.htm" class="MCXref xref" xrefformat="{paratext}">Data Types</a> in the Data pane. In many instances, you don't need to use a type conversion function at all. You can change the field's data type by clicking the icon. However, in some cases it can be useful to change the data type only for a specific calculation, or Tableau may not be able to correctly cast the field's contents to the desired data type (such as not recognizing the date format). Then you would need to use a type conversion function like those listed below. </p> <h2 is="heading-item" :level="2" id="type-conversion-functions-available-in-tableau"><a name="Type"/>Type conversion functions available in Tableau</h2> <td>Notes</td> <p>Unlike <a href="https://help.tableau.com/v0.0/pro/desktop/en-us/functions_functions_date.htm#dateparse" target="_blank">DATEPARSE<span class="sr-only">(Link opens in a new window)</span></a>, there is no need to provide a pattern as DATE automatically recognizes many standard date formats. If DATE does not recognize the input, however, try using DATEPARSE and specifying the format. <p><a href="https://help.tableau.com/v0.0/pro/desktop/en-us/functions_functions_date.htm#makedate" target="_blank">MAKEDATE<span class="sr-only">(Link opens in a new window)</span></a> is another similar function, but MAKEDATE requires the input of numeric values for year, month, and day. <td>Definition</td> <td>Casts its argument as an integer. For expressions, this function truncates results to the closest integer toward zero.</td> <td>Example</td> <td><pre xml:space="preserve">INT(8/3) = 2</pre><pre xml:space="preserve">INT(-9.7) = -9</pre> <td>Notes</td> <p>When a string is converted to an integer it is first converted to a float and then rounded.</p> <p>See also FLOAT which returns a decimal.<br/>See also <a href="https://help.tableau.com/current/pro/desktop/en-us/functions_functions_number.htm#round" target="_blank">ROUND<span class="sr-only">(Link opens in a new window)</span></a>, <a href="https://help.tableau.com/current/pro/desktop/en-us/functions_functions_number.htm#ceiling" target="_blank">CEILING<span class="sr-only">(Link opens in a new window)</span></a>, and <a href="https://help.tableau.com/current/pro/desktop/en-us/functions_functions_number.htm#floor" target="_blank">FLOOR<span class="sr-only">(Link opens in a new window)</span></a></p> <td>Definition</td> <td>Returns a datetime that combines a date and a time. The date can be a date, datetime, or a string type. The time must be a datetime.</td> <td>Example</td> <p/><pre>MAKEDATETIME("1899-12-30", #07:59:00#) = #12/30/1899 7:59:00 AM#</pre> <p/><pre>MAKEDATETIME([Date], [Time]) = #1/1/2001 6:00:00 AM#</pre> <td>Notes</td> <p>This function is available only for MySQL-compatible connections (which for Tableau are MySQL and Amazon Aurora). <p>MAKETIME is a similar function available for Tableau Data Extracts and some other data sources.</p> <td>Notes</td> <p>You can use MAKEPOINT to spatially-enable a data source so that it can be joined with a spatial file using a spatial join. For more information, see <a href="maps_spatial_join.htm" class="MCXref xref" xrefformat="{paratext}">Join Spatial Files in Tableau </a>. <p>To use MAKEPOINT, your data must contain latitude and longitude coordinates.</p> <td>Notes</td> <p>Because Tableau does not support a time data type, only date time, the output is a a datetime. The date portion of the field will be 1/1/1899. <p>Similar function to MAKEDATETIME, which is only available for MYSQL-compatible connections.</p> <h2 is="heading-item" :level="2" id="cast-boolean-expressions">Cast Boolean expressions</h2> <p>A Boolean can be cast to an integer, float, or string, but not a date. </p> <li><code>True</code>maps to 1, 1.0, or "1" </li> <li><code>False</code> maps to 0, 0.0, or "0"</li> <li><code>Unknown</code> maps to <code>Null</code></li> <h2 is="heading-item" :level="2" id="create-a-type-conversion-calculation"><a name="Create"/>Create a type conversion calculation </h2> <p>Follow along with the steps below to learn how to create a type conversion calculation.</p> <li value="1">In Tableau Desktop, connect to the <b>Sample - Superstore</b> saved data source, which comes with Tableau.</li> <li value="2">Navigate to a worksheet.</li> <li value="3">Select <span class="uicontrol">Analysis </span>> <span class="uicontrol">Create Calculated Field</span>.</li> <li value="4">In the calculation editor that opens, converts the Postal Code field from a number to a string: </li> <li>Name the calculated field, Postal Code String. <li>Enter the following formula: <p class="example"><code>STR([Postal Code])</code> </p></li> <li>When finished, click <b>OK</b>.</li> <p>The new calculated field appears under Dimensions in the <b>Data</b> pane. Just like your other fields, you can use it in one or more visualizations. </p> <p>Converting this field from a number to a string ensures that Tableau treats it as a string and not a number (and therefore doesn't aggregate it). </p> <h2 is="heading-item" :level="2" id="see-also">See Also</h2> <p><a href="datafields_typesandroles_datatypes.htm" class="MCXref xref" xrefformat="{paratext}">Data Types</a> <p><a href="data_dateparse.htm" class="MCXref xref" xrefformat="{paratext}">Convert a Field to a Date Field</a> <p><a href="functions_operators.htm" class="MCXref xref" xrefformat="{paratext}">Formatting Calculations in Tableau</a> <p><a href="functions.htm" class="MCXref xref" xrefformat="{paratext}">Functions in Tableau</a>
推荐文章
深情的扁豆
·
奈学p7数据分析架构师保薪班课程笔记 - 掘金
1 年前
有情有义的黑框眼镜
·
SyncLock Statement - Visual Basic | Microsoft Learn
1 年前