Tableau error Syntax

The calculation contains errors

Expected 'END' to match 'IF'

You wrote ELSE IF with a space. Tableau reads that as ELSE followed by a new IF, and that inner IF needs its own END. Write ELSEIF as one word.

Updated · Checked on the xmetric engine

Which formula raises it, and what fixes it?

Raises the error
IF [Profit] <= -1 THEN 1
ELSE IF [Profit] > 0 THEN 2
ELSE 3
END
Tableau: Expected 'END' to match 'IF'

The xmetric engine rejects it too.

Fixed
IF [Profit] <= -1 THEN 1
ELSEIF [Profit] > 0 THEN 2
ELSE 3
END

On each of the 3 example rows it returns:

RegionProfitResult
East42
West−21
West12

Why it works. ELSEIF continues the same IF, so one END closes everything. Nesting a real inner IF also works, but then it needs its own END: ... ELSE IF [Profit] > 0 THEN 2 ELSE 3 END END.

The 3 example rows
RegionProfit
East4
West-2
West1

What else raises this message?

  1. Raises it

    IF [Profit] > 100 THEN 'High'
    ELSE IF [Profit] > 0 THEN 'Low'
    END

    Fixed

    IF [Profit] > 100 THEN 'High'
    ELSEIF [Profit] > 0 THEN 'Low'
    END

    ELSE IF with a space opens a new IF that needs its own END. ELSEIF continues the same one.

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

  2. Raises it

    IF [Profit] < 0 THEN 'Loss'
    ELSE IF [Profit] = 0 THEN 'Even'
    ELSE 'Gain'
    END

    Fixed

    IF [Profit] < 0 THEN 'Loss'
    ELSEIF [Profit] = 0 THEN 'Even'
    ELSE 'Gain'
    END

    The same fix: one IF with ELSEIF, closed by one END.

    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?

Is ELSE IF ever correct?

Yes, if you close both IFs: IF a THEN x ELSE IF b THEN y ELSE z END END. ELSEIF is shorter and harder to get wrong.

Does the order of ELSEIF branches matter?

Yes. Tableau returns the first branch that is true, so put the narrowest tests first.

Where is this message documented?