Use if around two calculated fields with LAC

Hi,
I’ve these two formulas :
avg_base100 =
avg({price_average_eur})
/
avg(avg(ifelse({brand_name}=${pBrandReference},{price_average_eur},NULL),[{year_month}]))

min_base100 =
min({price_average_eur})
/
min(min(ifelse({brand_name}=${pBrandReference},{price_min_eur},NULL),[${pDateAgg}]))

All works but I’d like to provide a button to switch from one to the other, so I created a simple measure :
ifelse(${pMeasure}=“Min”,{avg_base100},{min_base100})

I’ve an error message ( The calculation operated on Level Aware Calculation (LAC) agg expressions is not valid).

Do you know how to write correctly this “if”?

Are you sure that both of these calculated fields work in a visual?

Is this error coming up when trying to calculate the calculated field or when you try and add it to a visual?

Hello,
Yes, both calculated fields work,
the issue is when I create the calculated field, by the way it works if I write something like
ifelse(test,calculation1, NULL) or
ifelse(test, calculation2, NULL) but not when I write
ifelse(test, calculation1, calculation2)

When you add these calculations to visuals what is the aggregation it shows?

They should both be custom.

1 Like

@Max Hello ^^,
yes they both have (Custom) aggregation by default.

Regards

@bherard ,

Please try using the LAC-W variant for this use case - avgOver, minOver with PRE_AGG mode.
I’m marking this as solution for now. Please let us know if you have more questions.

Regards,
Arun Santhosh

2 Likes

Hello,
it’s seems to work
I still don’t understand why it works with this solution and not with the other type of LAC
But thanks a lot anyway ^^