Calculated field problem

I am making a calculated field from some calculated fields.
the field is and its working!
image

everything is going well until I add a field, which has a different logic. When i add other field,
image

the field that gives me an error when adding is like this :
distinct_countIf({COD_PTO_VENTA}, {CALC_FECHA_VENTA}>=${pFechaDesde} and {CALC_FECHA_VENTA}<=${pFechaHasta})

and the others field are this: ifelse({CALC_FECHA_VENTA}>=${pFechaDesde} and {CALC_FECHA_VENTA}<=${pFechaHasta},
{CALC_MARGEN}, 0)

Can someone tell me why it gives this error?

Hi @Raulsc
Can you please specify what is the error? But it most likely because you are using aggregation. But description of the error will help confirm it.

Regards
Vetri

3 Likes

Hi @n_vetri ,

why is the aggregation? the field that is error is this: distinct_countIf({COD_PTO_VENTA}, {CALC_FECHA_VENTA} >= addDateTime(-1,‘YYYY’,${pFechaDesde}) and {CALC_FECHA_VENTA} <= addDateTime(-1,‘YYYY’,${pFechaHasta}))

how could change this field so?

Hi @Max , @Jesse , @Biswajit_1993 ,could you help me with this? thank you!

Either all the fields have to be aggregated, or none of them can be aggregated within a single calculated field. Assuming you are doing a SUM on the other 5 fields above it, wrap those in SUM to make them all aggregated (your last one already has aggregation (distinct count) built into it).

ifelse( param = ‘A’, sum(Margen ACT),
param = ‘B’, sum(Margen AA),

param = ‘F’, PDV Act),

2 Likes

its Working! But why? everything must be aggregation? Thanks!

Its true with most BI tools - in a single calculated field either all fields need to be aggregated or all need to be non-aggregate (same with Tableau and others). It has to do with the query pipeline.

1 Like