Tableau error Syntax

The calculation contains errors

Expected 'END' to match 'IF' at character 0

Your IF has no END. Every IF in Tableau closes with END; "character 0" points at the IF that is left open.

Updated · Checked on the xmetric engine

Which formula raises it, and what fixes it?

Raises the error
IF [Profit] > 0 THEN 'Profitable' ELSE 'Non-Profitable'
Tableau: Expected 'END' to match 'IF' at character 0

The xmetric engine rejects it too.

Fixed
IF [Profit] > 0 THEN 'Profitable'
ELSE 'Non-Profitable'
END

On each of the 3 example rows it returns:

RegionProfitResult
East4Profitable
West−2Non-Profitable
West1Profitable

Why it works. END closes the IF block. In a long formula the character number tells you which IF is open: count from 0 at the first character.

The 3 example rows
RegionProfit
East4
West-2
West1

What else raises this message?

  1. Raises it

    IF [Profit] > 0 THEN 'Yes'

    Fixed

    IF [Profit] > 0 THEN 'Yes' END

    Every IF ends with END, even without ELSE.

    Checked on the xmetric engine: the first fails, the fix runs.

  2. Raises it

    IF [Profit] > 0 THEN IF [Profit] > 2 THEN 'Big'
    ELSE 'Small'
    END

    Fixed

    IF [Profit] > 0 THEN IF [Profit] > 2 THEN 'Big'
    ELSE 'Small'
    END
    END

    A nested IF needs its own END, then the outer one closes too.

    Checked on the xmetric engine: the first fails, the fix runs.

Does my formula have this problem?

Paste your formula and run it on the example rows. It uses the fields [Region], [Profit]; rename yours to match.

Runs in your browser on the xmetric engine. Nothing is uploaded.

Which functions does this involve?

What do people ask about this error?

Can I write IIF instead to avoid END?

Yes, for a single test: IIF([Profit] > 0, 'Profitable', 'Non-Profitable'). IIF also handles unknown results with an optional fourth argument.

How many END do nested IFs need?

One per IF. With ELSEIF there is only one IF, so one END.

Where is this message documented?