Skip to main content
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.

1 Solution

Accepted Solutions
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

View solution in original post

16 Replies
alexandros17
Partner - Champion III
Partner - Champion III

Simply create a chart with product as dimension and add two expressions:

min(Id)

Max(id)

Hope it helps

manojkulkarni
Partner - Specialist II
Partner - Specialist II

From the data you provided, you will get only 2 rows

Product A  Min is 3 & Max is 16

Product B Min is 20 & Max is 27.

Do you have another requirement or condition to arrive the required results ?

luis_pimentel
Partner - Creator III
Partner - Creator III

Create a chart, with product as dimension an min(ID) and max(ID) as expressions

Anonymous
Not applicable
Author

I want to get this:

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

instead of this:

MinMaxProduct
316ProductA
2027ProductB

because the Id 8, 13 might belong to other product not ProductA and Id 22,24 not belong to ProductB as well.

sujeetsingh
Master III
Master III

you can do this in two ways :

1-In script by using Group By

2-In Ui by using the Dimension product and finding MIN & MAX

The one i have done in UI see the sample

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Yes, I do.

Use this:

ExtendedData:

LOAD ID,

    
IF (previous(Product) = Product,

       
IF (previous(ID) = ID-1, peek(Min), ID),

       
ID) AS Min,

    
ID AS Max,

    
Product AS ProductName

RESIDENT RawData;



Ranges:

LOAD ProductName,

    
Min AS RangeMin,

    
Max(Max) AS RangeMax

RESIDENT ExtendedData

GROUP BY ProductName, Min;

See also document below. Use table viewer to inspect table Ranges.

Good luck,

Peter

MK_QSL
MVP
MVP

Looks like the dimensions you have provided in not enough to get the desired result.

You might be missing the third dimension.

I have assumed the third dimension and created this document. Please check...

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Sorry, my script code window in Advanced Editor is going haywire. Had to correct the mess a bit. See the QVW for a working script.

Peter

alexandros17
Partner - Champion III
Partner - Champion III

I need more information about grouping logic ...