Skip to main content

Tableau Logical Functions

Tableau Logical Functions

Why do we use logical calculations?

Logical calculations allow you to determine if a certain condition is true or false (boolean logic). For example, you might want to quickly see if sales for each country you distribute your merchandise to were above or below a certain threshold.

FunctionSyntaxDescription
IN<expr1> IN <expr2>Returns TRUE if any value in <expr1> matches any value in <expr2>.
The values in <expr1> can be a Set, list of literal values, or a combined field.
Examples:
SUM([Cost]) IN (1000, 15, 200)
[SET] IN [COMBINED FIELD]
ANDIF <expr1> AND <expr2>
THEN <then>
END
Performs a logical conjunction on two expressions.
Example:
IF (ATTR([Market]) = "Africa" AND SUM([Sales]) > [Emerging Threshold] )THEN "Well Performing"
CASECASE <expression>
WHEN <value1> THEN <return1>
WHEN <value2> THEN <return2> ...
ELSE <default return>
END
Performs logical tests and returns appropriate values. The CASE function evaluates expression, compares
it to a sequence of values, value1, value2, etc., and returns a result. When a value that matches expression
is encountered, CASE returns the corresponding return value. If no match is found, the default return expression
is used. If there is no default return and no values match, then Null is returned.
CASE is often easier to use than IIF or IF THEN ELSE.
Typically, you use an IF function to perform a sequence of arbitrary tests, and you use a CASE function to search
for a match to an expression. But a CASE function can always be rewritten as an IF function , although
the CASE function will generally be more concise.
Many times you can use a group to get the same results as a complicated case function.
Examples:
CASE [Region] WHEN 'West' THEN 1 WHEN 'East' THEN 2 ELSE 3 END
CASE LEFT(DATENAME('weekday',[Order Date]),3) WHEN 'Sun' THEN 0 WHEN 'Mon' THEN 1
WHEN 'Tue' THEN 2 WHEN 'Wed' THEN 3 WHEN 'Thu' THEN 4 WHEN 'Fri' THEN 5 WHEN 'Sat' THEN 6 END
ELSEIF <expr> THEN <then>
ELSE <else>
END
Tests a series of expressions returning the <then> value for the first true <expr>.
Example:
If [Profit] > 0 THEN 'Profitable' ELSE 'Loss' END
ELSEIFIF <expr> THEN <then>
[ELSEIF <expr2> THEN <then2>...]
[ELSE <else>]
END
Tests a series of expressions returning the <then> value for the first true <expr>.
Example:
IF [Profit] > 0 THEN 'Profitable' ELSEIF [Profit] = 0 THEN 'Breakeven' ELSE 'Loss' END
ENDIF <expr> THEN <then>
[ELSEIF <expr2> THEN <then2>...]
[ELSE <else>]
END
Tests a series of expressions returning the <then> value for the first true <expr>. Must be placed at the end
of an expression.
Example:
IF [Profit] > 0 THEN 'Profitable' ELSEIF [Profit] = 0 THEN 'Breakeven' ELSE 'Loss' END
IFIF <expr> THEN <then>
[ELSEIF <expr2> THEN <then2>...]
[ELSE <else>]
END
Tests a series of expressions returning the <then> value for the first true <expr>.
Example:
IF [Profit] > 0 THEN 'Profitable' ELSEIF [Profit] = 0 THEN 'Breakeven' ELSE 'Loss' END
IFNULLIFNULL(expr1, expr2)Returns <expr1> if it is not null, otherwise returns <expr2>.
Example:
IFNULL([Profit], 0)
IIFIIF(test, then, else, [unknown])Checks whether a condition is met, and returns one value if TRUE, another value if FALSE, and an optional third value
or NULL if unknown.
Example:
IIF([Profit] > 0, 'Profit', 'Loss')
ISDATEISDATE(string)Returns true if a given string is a valid date.
Example:
ISDATE("2004-04-15") = True
ISNULLISNULL(expression)Returns true if the expression is NULL (does not contain valid data).
Example:
ISNULL([Profit])
MAXMAX(expression) or
Max(expr1, expr2)
Returns the maximum of a single expression across all records or the maximum of two expressions for each record.
Example:
MAX([Sales])
MINMIN(expression) or
MIN(expr1, expr2)
Returns the minimum of an expression across all records or the minimum of two expressions for each record.
Example:
MIN([Profit])
NOTIF NOT <expr> THEN <then> ENDPerforms logical negation on an expression.
Example:
IF NOT [Profit] > 0 THEN "Unprofitable" END
ORIF <expr1> OR <expr2> THEN <then> ENDPerforms a logical disjunction on two expressions.
Example:
IF [Profit] < 0 OR [Profit] = 0 THEN "Needs Improvement" END
THENIF <expre> THEN <then> [ELSEIF ,expr2> THEN <then2>...] [ELSE <else>] ENDTests a series of expressions returning the <then> value for the first true <expr>.
Example:
IF [Profit] > 0 THEN 'Profitable' ELSEIF [Profit] = 0 THEN 'Break even' ELSE 'unprofitable' END
WHENCASE <expr> WHEN <Value1> THEN <return1> ... [ELSE <else>] ENDFinds the first <value> that matches <expr> and returns the corresponding <return>.
Example:
CASE [RomanNumberal] WHEN 'I' THEN 1 WHEN 'II' THEN 2 ELSE 3 END
ZNZN(expression)Returns <expression> if it is not null, otherwise returns zero.
Example:
ZN([Profit])

Comments

Popular Posts

Add Space between bars in Tableau chart

Add Space between bars in Tableau chart Scenario: Tableau defaults to no spacing between the panes in a view. How do I get some spacing between groups of bars in my charts? It can be achieved through the steps below: Add subtotals (Analysis->Totals->Add All Subtotals) Right click on the measure pill on the Rows shelf and change the default SUM() aggregations to MIN() To edit the color legend – double click on the Total color, this takes you to a color dialog, select the WHITE color, click OK Right click on the word Total in the X axis and select Format In the Format window, click the Header tab and blank out the Total label field The added space looks like below:

Error "Cannot mix aggregate and non-aggregate arguments with this function"

Error "Cannot mix aggregate and non-aggregate arguments with this function" When Creating a Calculated Field When creating a calculation, the following error might occur:  "Cannot mix aggregate and non-aggregate arguments with this function." The issue can be resolved through one of the below options: Modify the calculation so that all fields are either aggregate or non-aggregate. Each option can result in different values (please reference the additional information section for specific examples). Option 1 (Aggregate Then Divide) Wrap all fields in an aggregation. Sample: [Profit] / SUM ([Sales]) -> SUM ([Profit]) / SUM ([Sales]) Option 2 ( Divide Then Aggregate) Remove aggregations from all of the fields. Sample: [Profit] / SUM ([Sales]) ->[Profit] / [Sales]   Option 3 ( Condition Then Aggregate) Move the aggregation so all fields are aggregated. For example, the calculation: IF [Row ID] = 1 THEN SUM( [Sales] ) END  could become:

Adding “Apply” Button to A Filter Menu In Tableau

Adding An “Apply” Changes Button To A Filter Menu In Tableau Sometimes when a user is changing the options they want on a filter in Tableau, the chart updates as they change each option. This might not be the best user experience if they are changing many options and don’t want the dashboard to redraw the view until they have completed their selection. It is very simple to fix this – Tableau includes an “apply” changes option, which when enabled, means the dashboard won’t redraw to reflect the new filter choices until the user presses the “apply” button. Simply click the drop down arrow on the filter menu > go to “customize”, then click “show apply button”.  

Removing "Abc" Placeholder Text in Tableau Measures column

Removing "Abc" Placeholder Text in Tableau Measures column Quick and easy fix for this issue could be: Use Polygon mark type On the Marks card in the dropdown menu, select Polygon Resize the last column to make it smaller Navigate to Format > Borders In the left-hand Format Border Pane, for Column Divider, For Pane, select None from the dropdown menu Navigate to Format > Shading In the left-hand Format Border Shading, for Row Banding, move the slider to the desired level of row banding

Tableau Bar Chart Rounded corners

Tableau Bar Chart Rounded corners Follow the steps in the video below to create rounded corners for the bar chart:

Using Special Characters in Tableau URL Parameters

Using Special Characters in Tableau URL Parameters When we try to use special characters in URL parameters, the URL parameter might not do anything, or an error might occur. The issue can be resolve by:  Use one of the following workarounds: Replace the special character with the URL encoding sequence for backslash (\) (%5c) followed by the URL encoding sequence for the special character. The backslash is needed to escape the special character. For example, the URL encoding sequence for backslash and comma (\,) is %5c%2c.  In the data source, separate comma-delimited field values into separate columns that can be filtered independently. In Tableau Desktop, use a calculated field to replace the special characters, such as commas or spaces, with hyphens (-). Cause The browser cannot parse the special characters used in the URL. Additional Information The error varies depending on the browser and special character being used. Network Working Group:  Uniform Resource

Cannot mix aggregate and non-aggregate arguments with this function

Cannot mix aggregate and non-aggregate arguments with this function Issue When creating a calculation, one of the following errors might occur:    "Cannot mix aggregate and non-aggregate arguments with this function." (Option 1,2,3 or 4 can be used). " All fields must be aggregate or constant when using table calculation functions or fields from multiple data sources." (Option 1 or 3 can be used). "Argument to sum (an aggregate function) is already an aggregation, and cannot be further aggregated ."  (Option 2, 3 or 4 can be used). Environment Tableau Desktop Resolution Each option can result in different values (please reference the attached workbook in the right-hand pane and additional information section for specific examples). Option 1 (Aggregate All Fields) Wrap all fields in an aggregation. Sample: [Profit] / SUM ([Sales]) -> SUM ([Profit]) / SUM ([Sales])   Option 2 ( De-aggregate All Fields) Remove aggregations from all of

Set a Date Filter Default to Max Date in Tableau

Set a Date Filter Default to Max Date in Tableau Some of us might have not noticed the setting a   filter to default to the Max date. There is a quick and simple option to achieve this in Tableau filters. Follow the steps below: 1. Create a date filter with the date dimension. 3. Drag the date dimension to filters pane. 4. Edit the date filter to Select from the list and select the max date available. 2.    Now, y ou have the option  'Filter to latest date value when workbook is opened', check this box and click on OK.

Tableau Extract Update Error "Timeout Error: IPC_NamedPipe::Select(WaitForMultipleObjects)

Tableau Extract Update Error "Timeout Error: IPC_NamedPipe::Select(WaitForMultipleObjects) When trying to update the Data Source or w hen attempting to connect to a data source, or create and/or refresh extracts with Tableau Desktop, the following error message occurs:  IPC_NamedPipe::Select(WaitForMultipleObjects): Timeout. Cause Anti-virus software is blocking Tableau processes from running, or the Logs folder contained corrupted information.  Resolution Option 1: If it is easy w ork with IT helpdesk/support to add below Tableau folders and processes to exclusions : Tableau.exe hyperd.exe hyperdstarter.exe *.hyper extension (if AntiVirus has an option for extension exclusions) C:\Users\<username>\Documents\My Tableau Repository C:\Users\<username>\AppData\Local\Temp\TableauTemp C:\Users\<username>\AppData\Local\Tableau C:\Program Files\Tableau Make sure that child folders are included in the exclusions. AntiVirus programs may