8 Replies Latest reply on Sep 6, 2018 3:35 AM by Ravi Mistry

# Multiple IF ELSE IF STATMENTS for different measures

Hi all,

I'm trying to build this multiple logical expression, somehow it is throwing error even if I put end at the bottom. Please can some one guide me with the correct formula.

Can we achieve this in tableau?

avg(IF  [Alias Segreggate (copy)] =  "Age" then [KRI Value])
Avg(ELSEIF [Alias Segreggate (copy)] =  "CONC" then [KRI Value] )
SUM(ELSEIF [Alias Segreggate (copy)] =  "COUNT" then [KRI Value])
SUM(ELSEIF [Alias Segreggate (copy)] =  "Financial Values" then [KRI Value] )
SUM(ELSEIF [Alias Segreggate (copy)] =  "OTHERS" then [KRI Value])
avg(ELSEIF [Alias Segreggate (copy)] =  "per1000" then [KRI Value])
avg(ELSEIF [Alias Segreggate (copy)] =  "Ratio" then [KRI Value] )
sum(ELSEIF [Alias Segreggate (copy)] =  "Volume" then [KRI Value] )

END

thanks

• ###### 1. Re: Multiple IF ELSE IF STATMENTS for different measures

Hey Sowjanya,

What error are you getting, could you share a screenshot? What behaviour are you expecting?

Best,

Ravi

• ###### 2. Re: Multiple IF ELSE IF STATMENTS for different measures

sometimes it is saying END is mission and sometimes it is showing expected parenthesis.

thanks

• ###### 3. Re: Multiple IF ELSE IF STATMENTS for different measures

OK! I think I understand - try this... It looks like your syntax and order was a bit off!

Hope this works!

IF  [Alias Segreggate (copy)] =  "Age" then avg([KRI Value])

ELSEIF [Alias Segreggate (copy)] =  "CONC" then avg([KRI Value] )
ELSEIF [Alias Segreggate (copy)] =  "COUNT" then SUM([KRI Value])
ELSEIF [Alias Segreggate (copy)] =  "Financial Values" then SUM([KRI Value] )
ELSEIF [Alias Segreggate (copy)] =  "OTHERS" then SUM([KRI Value])
ELSEIF [Alias Segreggate (copy)] =  "per1000" then AVG([KRI Value])
ELSEIF [Alias Segreggate (copy)] =  "Ratio" then AVG([KRI Value] )
ELSEIF [Alias Segreggate (copy)] =  "Volume" then SUM([KRI Value] )

END

• ###### 4. Re: Multiple IF ELSE IF STATMENTS for different measures

Hi Ravi,

• ###### 5. Re: Multiple IF ELSE IF STATMENTS for different measures

Try putting Attr before  [Alias Segreggate (copy) in the whole formula

1 of 1 people found this helpful
• ###### 6. Re: Multiple IF ELSE IF STATMENTS for different measures

Hi Sowjanya,

Can you check whether this works;

CASE ATTR([Alias Segreggate (copy)])

WHEN  "Age" then avg([KRI Value])

WHEN  "CONC" then avg([KRI Value] )
WHEN "COUNT" then SUM([KRI Value])
WHEN "Financial Values" then SUM([KRI Value] )
WHEN  "OTHERS" then SUM([KRI Value])
WHEN  "per1000" then AVG([KRI Value])
WHEN"Ratio" then AVG([KRI Value] )
WHEN  "Volume" then SUM([KRI Value] )

END

• ###### 7. Re: Multiple IF ELSE IF STATMENTS for different measures

Even this is correct.

thanks a lot for your help.

• ###### 8. Re: Multiple IF ELSE IF STATMENTS for different measures

Awesome! Glad you got it sorted