6 Replies Latest reply on Dec 17, 2015 12:13 PM by Joe Oppelt

# Error: Expected Type Float, Found String

Hi, I am trying to set up a conditional statement that takes the above formula only when it is not a promo week. Not sure what the error message here is saying.  Any ideas on how to fix the formula?

Units and Price Change are table calculations

(ZN(SUM([Non Promo Price])) - LOOKUP(ZN(SUM([Non Promo Price])), -1)) / ABS(LOOKUP(ZN(SUM([Non Promo Price])), -1))

(ZN(SUM([Units])) - LOOKUP(ZN(SUM([Units])), -1)) / ABS(LOOKUP(ZN(SUM([Units])), -1))

Here is a view of the data, the measures to be divided are the last two columns, the rest need to be blanks when Count of Promo Week is a 1.

• ###### 1. Re: Error: Expected Type Float, Found String

change that to

ELSE NULL END

ELSE "" END

1 of 1 people found this helpful
• ###### 2. Re: Error: Expected Type Float, Found String

It also works like this...

IF ATTR([PROMO WEEK]) = 0 THEN [Units % Chg on Base Price Chg]/[Non Promo Price % Chg] END

• ###### 3. Re: Error: Expected Type Float, Found String

Using quotes makes a character string.

In fact, you could eliminate the entire ELSE portion, because tableau defaults to NULL for the ELSE condition if you don't specify an ELSE clause.

1 of 1 people found this helpful
• ###### 4. Re: Error: Expected Type Float, Found String

Are you all set with this?  Do you understand what the error meant?

• ###### 5. Re: Error: Expected Type Float, Found String

I think I may understand, but missing a bit of the nuance.

Here is my next attempt at a similar type of calculation....

calculation is said to be valid but returns no values even though there are values for all variables....

• ###### 6. Re: Error: Expected Type Float, Found String

First let me tell you about the first error.

A general IF statement has this format:

IF (something) THEN (A) ELSE (B) END

The (A) and (B) both have to be of the same datatype.  In your original example, your (A) portion was numeric, and your (B) portion was STRING because it was something (in that example, NULL) enclosed in quotes.  The keyword NULL in and of itself satisfies a numeric result (or a date result), so changing "" to NULL took care of the error.

You can omit the 'ELSE (B)' part of an IF statement.  If you do, Tableau assumes you want NULL and inserts it implicitly for you.  (If you have a string value for (A), then tableau inserts "" as the ELSE value for you.)

In your latest example you have a valid syntax.  I notice that you are doing ATTR([PB PROMO WEEK]).  You might want to be doing SUM([PB PROMO WEEK]) since that's the measure you are displaying on this sheet.  ATTR says to do the operation at the data row level.  SUM does it within the context of the various dimensions involved.  The two are equivalent only if there is only one database row for each combo of dimensions on the sheet.

I could be more specific in my answer here if I have a sample workbook of what you are doing.  Maybe this takes care of it for you, but if you have more questions it will serve us both if you could provide a packaged workbook so I can give more specific answers.