Adhoc calculations are calculations that you can create and update as you work with a field on a shelf in the view. Adhoc calculations are also known as typein or inline calculations.
Create an AdHoc Calculation
Doubleclick on an existing field to start editing. 

You can also doubleclick on an empty shelf or on an empty part of a shelf to create a new calculation. 

Type to update the expression, or drag new fields into the expression from the Data pane or elsewhere in the view. 

Press Enter, Tab, or click outside the expression to commit the expression, close the calculation, and update the view. Press Ctrl+Enter (or Command+Enter on a Mac) to commit the expression and update the view without closing the calculation. 

Adhoc calculations are supported on the Rows, Columns, Marks, and Measure Values shelves; they are not supported on the Filters or Pages shelves.
If you are working in Tableau Desktop, errors in adhoc calculations are underlined in red. Hover over the error to see a suggestion for resolving it.
Note: Adhoc calculations are not named, but are saved when you close the workbook. If you want to save an adhoc calculation for use in other workbook sheets, copy it to the Data pane. You will be prompted to name the calculation. {On server it just deposits it w/o rename prompt.} Once you name an adhoc calculation, it is the same as a calculation you created with the calculation editor, and is available on other sheets in the workbook. See Get Started with Calculations in Tableau
MultiLine AdHoc Calculations
As you're typing an adhoc calculation, you can press Shift+Enter to start a new line. However, only the current line is ever visible in an adhoc calculation, so this can be confusing for anyone viewing or editing the calculation who has no way of knowing that it contains multiple lines.
The first line of a multiline adhoc calculation can be a comment that serves as a title for the calculation. This is the only line that is visible on the shelf after the calculation is committed:
//City and State
[City] + ', ' + [State]
AdHoc Calculations and Aggregation
If Tableau determines that the expression you enter is a measure (that is, returns a number), it automatically adds an aggregation to the expression when you commit the expression. For example, if you type DATEDIFF('day',[Ship Date],[Order Date])
in an adhoc calculation and then press Enter, what you will see is the following:
SUM(DATEDIFF('day',[Ship Date],[Order Date]))
If you use a field that is already an aggregated field (for example, SUM([Profit])) in an adhoc calculation, the result is an aggregate calculation. For example, when you commit an adhoc calculation SUM([Profit])/SUM([Sales])
, the result is:
AGG(SUM([Profit])/SUM([Sales]))
For more information on aggregate calculations, see Aggregate Functions in Tableau(Link opens in a new window).
AdHoc Calculations for Insight and Experimentation
Typically you create adhoc calculations onthefly to do things like

Test a hunch

Try a whatif scenario

Debug a complex calculation
Managing AdHoc Calculations
Use the following keystrokes to manage adhoc calculations.

Doubleclick in an existing field on the Rows, Columns, Marks, or Measure Values shelf to open it as an adhoc calculation.

Doubleclick elsewhere on any of these shelves to create a new adhoc calculation from scratch.

Press Esc to cancel an adhoc calculation.

Press Enter to commit an adhoc calculation, which updates the view and closes the adhoc calculation. Press Ctrl+Enter to commit the change and update the view without closing the adhoc calculation.

If you are working in Tableau Desktop, and there is a field to the right of the current adhoc calculation on the same shelf, pressing Tab opens that field as an adhoc calculation. If there is no field to the right of the current adhoc calculation on the shelf, pressing Tab opens a new adhoc calculation. Shift+Tab has the same functionality, except it moves to the left.

When you doubleclick a named field on a shelf to edit it, you are not changing the original named field.
In addition, the following rules govern the use of adhoc calculations.

Only one adhoc calculation can be open at a time.

If a field that has a geographic role or a fiscal year setting associated with it is added to an adhoc calculation, the adhoc calculation inherits that role or setting.

The rightclick context menu for an adhoc calculation supports the same options that would be available for any other field in the view of the same type, including the ability to change aggregation or format.

Adhoc calculations are not available when you create groups, sets, hierarchies, or parameters.

Adhoc calculations are valid for creating trend lines, forecasts, and reference lines, bands, and distributions.