Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

FOREACH in expressions

Hi everybody,

i have this table

IDDEVICE     IDFIELD     ENERGY             

a                    1                    50                       

a                    1                    40                        

b                    1                    70                   

b                    1                    60                   

c                    1                    100                   

c                    1                    110                   

d                    2                    100                   

d                    2                    10                   

e                    2                    205                   

e                    2                    200                  

f                      3                    10                  

g                         4               15                  

Does exist some kind of FOREACH that i can use like this:

if (  IDFIELD = 1,

FOREACH IDDEVICE take max(ENERGY)

)+

if (  IDFIELD = 2,

FOREACH IDDEVICE take max(ENERGY)

)+

.....

1 Solution

Accepted Solutions
swuehl
MVP
MVP

What do you do with the list of max(Energy) values then? Sum them up?

Could you give an example of your expected outcome?

Maybe you could use something like

=sum( {<IDFIELD={1}>} aggr(max( {<IDFIELD={1}>} ENERGY), IDDEVICE))

View solution in original post

6 Replies
CELAMBARASAN
Partner - Champion
Partner - Champion

Hi,

     Did you expect this in script expression?

     If so then you can do this by using group by like

          Load

                    IDFIELD,

                    Max(ENERGY)

          Resident

                    TableName

          GROUP BY IDFIELD;

Hope it helps

Celambarasan

swuehl
MVP
MVP

What do you do with the list of max(Energy) values then? Sum them up?

Could you give an example of your expected outcome?

Maybe you could use something like

=sum( {<IDFIELD={1}>} aggr(max( {<IDFIELD={1}>} ENERGY), IDDEVICE))

Anonymous
Not applicable
Author

SWUEHL

Yes i want the SUM and your expression works good.

In the same way, can i group by IDFIELD too ?

swuehl
MVP
MVP

Probably yes,

(I am not 100% sure what you are looking for, again, describing your expected outcome might help here):

try

=sum( aggr(max( ENERGY), IDFIELD, IDDEVICE))

Anonymous
Not applicable
Author

SWUEHL

one last question:

Now i want to take the Min value of energy but only where ENERGY > 0

=sum( aggr(MIN( ENERGY), IDFIELD, IDDEVICE))


i'm trying to put    IF(ENERGY>0,......)      everywhere in the expression but seems not working...

thanks

swuehl
MVP
MVP

Try a set expression

=sum({<ENERGY = {">0"}>} aggr(MIN({<ENERGY = {">0"}>} ENERGY), IDFIELD, IDDEVICE))