Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
googel84
Partner - Creator III
Partner - Creator III

Nested aggregation not allowed issue

Hi community, I am facing a quite strange issue, at least to my eyes.

I am setting the following formula while in a script variable, as I did many other times.

SET vFatturatoYTD_AnnoPiuRecente =

     "sum({$< DATA_MOV_MAG.ANNO = {'=$(vAnnoPiuRecente)'} >}

          if( inyeartodate(

                    DATA_MOV_MAG,

                    makedate($(vAnnoPiuRecente),num(month('$(vDataBase)')),num(day('$(vDataBase)'))),

                    0),

              VALORE_EURO,

               0

          )

     )";

where

vAnnoPiuRecente = "max(DATA_MOV_MAG.ANNO)"

and vDataBase is calculated as the date of the main QVD last reload minus 1.

This time, though, when it comes to use the variable in question in a chart (or even in a text object), I get the following error:

Nested aggregation not allowed

For this reason, I was forced to define multiple expressions very similar to the formula cited above, one for each chart I would have wanted to use the variable. Here it is the expression:

sum({$< DATA_MOV_MAG.ANNO = {$(=$(vAnnoPiuRecente))} >}

     if( inyeartodate(

            DATA_MOV_MAG,

            makedate($(=$(vAnnoPiuRecente)),num(month('$(vDataBase)')),num(day('$(vDataBase)'))),

            0),

       VALORE_EURO,

       0

    )

)

See the attached sample application for further details.

Thanks in advance.

1 Solution

Accepted Solutions
Gysbert_Wassenaar

Try defining vAnnoPiuRecente like this:

SET vAnnoPiuRecente =  "=max(DATA_MOV_MAG.ANNO)";

The extra = sign in front of the max will cause the variable to be calculated outside the context of the expression it's used in.

If you do need it to be calculated in context of the chart then you need to use the aggr function. Basically sum(max(Value)) cannot be calculated without additional information. So you need something like sum(aggr(max(Value),Dim1, Dim2, ..., DimX)). That way you get a list of max values per Dim1,Dim2,...,DimX combination. That is a list of values that can be summed.


talk is cheap, supply exceeds demand

View solution in original post

1 Reply
Gysbert_Wassenaar

Try defining vAnnoPiuRecente like this:

SET vAnnoPiuRecente =  "=max(DATA_MOV_MAG.ANNO)";

The extra = sign in front of the max will cause the variable to be calculated outside the context of the expression it's used in.

If you do need it to be calculated in context of the chart then you need to use the aggr function. Basically sum(max(Value)) cannot be calculated without additional information. So you need something like sum(aggr(max(Value),Dim1, Dim2, ..., DimX)). That way you get a list of max values per Dim1,Dim2,...,DimX combination. That is a list of values that can be summed.


talk is cheap, supply exceeds demand