Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to get min and max id

Hello Community,

I want to get the min id and max id for the product. I have data like below:

                                                                         

IDProduct
3ProductA
4ProductA
5ProductA
6ProductA
7ProductA
9ProductA
10ProductA
11ProductA
12ProductA
14ProductA
15ProductA
16ProductA
20ProductB
21ProductB
23ProductB
25ProductB
26ProductB
27ProductB

This is what i want to get:

                                        

MinMaxProduct
37ProductA
912ProductA
1416ProductA
2021ProductB
2323ProductB
2527ProductB

Anyone got idea how to get this? Thanks in advance.

16 Replies
Not applicable
Author

With provided information you get only two values. Please add another dimension and use the group by clause in the script to get the aggregated data in the script.

kumarnatarajan
Partner - Specialist
Partner - Specialist

Hi,

Try the below script,

1. Lead the below mentioned script

2. add chart (stright table)

    Dimention: Product and ID1 

    Experesion : Max(ID) and Min(ID)

3. (Hide ID1 Column) go to chart properties _> prasentation -> click ID1 column and check hide colimn.

Script:

 

LOAD

ID,Product,if(len(trim(Peek(ID)))=0,ID,if((ID-Peek(ID))=1,Peek(ID1),ID)) as ID1

INLINE

[
ID, Product
3, ProductA
4, ProductA
5, ProductA
6, ProductA
7, ProductA
9, ProductA
10, ProductA
11, ProductA
12, ProductA
14, ProductA
15, ProductA
16, ProductA
20, ProductB
21, ProductB
23, ProductB
25, ProductB
26, ProductB
27, ProductB
]

;

Anonymous
Not applicable
Author

Thanks Peter.

But what if there are subgroup in my data:

IDProduct
3ProductA
4ProductA
5ProductA
6ProductA
7ProductA
9ProductA
10ProductA
11ProductA
12ProductA
14ProductA
15ProductA
16ProductA
20ProductB
21ProductB
23ProductB
25ProductB
26ProductB
27ProductB
3ProductA1
4ProductA2
5ProductA3
6ProductA4
7ProductA5
9ProductA6
10ProductA7
11ProductA8
12ProductA9
14ProductA10
15ProductA11
16ProductA12
20ProductB1
21ProductB2
23ProductB3
25ProductB4
26ProductB5
27ProductB6

and i expect something like this?

MinMaxProduct
37ProductA
912ProductA
1416ProductA
2021ProductB
2323ProductB
2527ProductB
33ProductA1
44ProductA2
55ProductA3
66ProductA4
77ProductA5
99ProductA6
1010ProductA7
1111ProductA8
1212ProductA9
1414ProductA10
1515ProductA11
1616ProductA12
2020ProductB1
2121ProductB2
2323ProductB3
2525ProductB4
2626ProductB5
2727

ProductB6

Anonymous
Not applicable
Author

Thanks all for your reply. But max(ID) and Min(ID) won't return what i want. There are only 2 columns in my table which are Product and ID, there is no 3rd column/dimension

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Well, in my example I assumed the table would be ordered by unique ID. If this isn't the case, then order your table by product first, and then by ID.  The code will still work. In the below example I only changed the input data.

Good luck,

Peter

Anonymous
Not applicable
Author

Thanks Peter for your quick response

Not applicable
Author

How do you know the ProductA got changed at ID value 8 ?