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: 
Not applicable

max and group by in script

Hi all,

I have data like the following:

Id

Seg

1

260

1

144

1

555

2

628

2

953

2

876

2

212

3

142

3

123



Load

Id,

Seg

Resident tab1 group by id;

I need to achieve the following result:

Id

Final Seg

1

144

2

953

3

142



where

Final Seg = if(Seg >=140 and Seg <=146, Seg, max(Seg))

Any idea is highly appreciated. Thanks a lot!

1 Solution

Accepted Solutions
Not applicable
Author

Hi Yacine,

Here you are my possible solution.

I hope it works for you.

I have a doubt, ¿what would happen if you found two values in range for the same Id?

Best regards.

View solution in original post

6 Replies
Not applicable
Author

Hi Yacine,

Here you are a possible solution.

Best regards.

shumailh
Creator III
Creator III

Try this expression in ur table,


IF(SEG>=140 AND SEG<=146, SUM(SEG), MAX(SEG))


Regards,
Shumail Hussain

Not applicable
Author

Hi,

Thanks for your reply. It works but not exactly what I need. I need the max of each Id, not the max of the whole list.

Thanks.

Not applicable
Author

Hi ,

Can you explain how do you wanna get the result table then? because I don't understand the approach if you need the max of each Id, by example, for the records ID = 1, if Seg > = 140 and Seg <= 146 then Seg else Max(Seg), how do you get the table result id=1 Final Seg=144 for the three records? 1 - 144, 1 - 260 and 1 - 555?.

Best regards.

Not applicable
Author

Hi,

for each Id

if one of the values (Seg) is in the interval [140 - 146] then

finalSeg = Seg

else // no Seg value in the interval

finalSeg = the max Seg value (for this Id)

end

end

Thanks.

Not applicable
Author

Hi Yacine,

Here you are my possible solution.

I hope it works for you.

I have a doubt, ¿what would happen if you found two values in range for the same Id?

Best regards.