6 Replies Latest reply on Jan 8, 2019 1:49 PM by Michel Caissie

# Help with LOD calculation

I need to write a IF else LOD calculation something like this :

IF [customer_name] = ''mark"

Then { Fixed [customer_name], [company_name] : sum([product sales])}

Else  { Fixed [customer_name], [company_name] : sum([Profits])}

END

when i write this condition i am not seeing the numbers i expect to see. what am i doing wrong here? is there a different way to calculate this using Tableau LOD calculations?

• ###### 1. Re: Help with LOD calculation

I am sure this syntax will need to be tweaked but

try moving the conditional inside the lod {fixed customername,companyname: sum(  if [customername]='mark' then [sales] else[profit]   end)}

Jim

If this posts assists in resolving the question, please mark it helpful or as the 'correct answer' if it resolves the question. This will help other users find the same answer/resolution.  Thank you.

1 of 1 people found this helpful
• ###### 2. Re: Help with LOD calculation

Thank you !

• ###### 3. Re: Help with LOD calculation

thank you

Jim

1 of 1 people found this helpful
• ###### 4. Re: Help with LOD calculation

how can  i solve this issue for this calculation: cannot mix aggregate and non aggregate comparisons or results in 'IF' expressions

IF [customer_name] =  'mark'

Then  SUM (Sales) / SUM ( Total orders)

Else  SUM (profits) / SUM ( Total orders)

END

• ###### 5. Re: Help with LOD calculation

Hi mark

whenever any of the dimensions or measures are aggregated in a calculation then all must be aggregated - in your case customer name is not aggregated - yes I know "How do you aggregate a text field"

you can use attr()  and it will work but when you are working with LOD's you cant use attr() so I usually use min() or Max()  YOu may need to play with it and see what works in your real data

Jim

• ###### 6. Re: Help with LOD calculation

Mark,  do the  row level logic first  then the aggregation.

SUM(if [customer_name] = 'mark'  then  Sales else profits end)   /  SUM (Total orders)