5 Replies Latest reply on Aug 13, 2018 8:18 AM by priti.shah.0

# Error: Cannot mix Aggregate and non aggregate comparison in if expressions

Hi,

I'm trying to get this formula work but I'm getting

Error: Cannot mix Aggregate and non aggregate comparison in if expressions

If Acct type is "R" then Actual - Budget else Budget - Actual.

(If [Actual Flag]="A" THEN

(IF [Account Type]= "R" THEN SUM([RR-CM Actual])-SUM([RR-CM Budget]) ELSE SUM([RR-CM Budget])-SUM([RR-CM Actual]) END)

END)

-Priti

• ###### 1. Re: Error: Cannot mix Aggregate and non aggregate comparison in if expressions

Hi, Priti

Try this

(If Min([Actual Flag])="A" THEN

(IF Min([Account Type])= "R" THEN SUM([RR-CM Actual])-SUM([RR-CM Budget]) ELSE SUM([RR-CM Budget])-SUM([RR-CM Actual]) END)

END)

ZZ

• ###### 2. Re: Error: Cannot mix Aggregate and non aggregate comparison in if expressions

Hi Priti,

Try this below Calculation

(If ATTR([Actual Flag])="A" THEN

(IF ATTR([Account Type])= "R" THEN SUM([RR-CM Actual])-SUM([RR-CM Budget]) ELSE SUM([RR-CM Budget])-SUM([RR-CM Actual]) END)

END)

Kindly mark this answer as helpful or correct so that it will help others

BR,

NB

• ###### 3. Re: Error: Cannot mix Aggregate and non aggregate comparison in if expressions

TRY THIS:

SUM(If [Actual Flag]="A" THEN

(IF [Account Type]= "R" THEN [RR-CM Actual]-[RR-CM Budget] ELSE [RR-CM Budget]-[RR-CM Actual] END)

END))

• ###### 4. Re: Error: Cannot mix Aggregate and non aggregate comparison in if expressions

Hi,

If its only related to fix the error you can use ATTR() on your [Acutal Flag] dimension.

But you said, If Acct type is "R" then Actual - Budget else Budget - Actual

Just curious why did you put condition on [Actual Flag]="A" ?? If the said statement is correct then it'd would be something like this

IF ATTR([Actual Flag])="R"

THEN SUM([RR-CM Actual])-SUM([RR-CM Budget])

ELSE SUM([RR-CM Budget])-SUM([RR-CM Actual])

END

Let us know if this help

Mahfooj

• ###### 5. Re: Error: Cannot mix Aggregate and non aggregate comparison in if expressions

Thanks All whoever answered the question.

based on your reply I learn that I need to put aggregate function on both side. this will help.

Thanks.