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

Trouble with Max Function

Hello dear community, I'm having a hard time with the max function. I'll try to explain my problem the best way I can.

I have the following data set:

VersionID.PNG

What I want to do, is get all the product ID's that have the highest ID version.

So according to the data set, with the correct script, I should get:

VersionID2.PNG

Hope you can help me.

Best Regards.

1 Solution

Accepted Solutions
MarcoWedel

one example:

QlikCommunity_Thread_166605_Pic2_.JPG

tabInput:

LOAD * FROM [https://community.qlik.com/thread/166605] (html, codepage is 1252, embedded labels, table is @2);

Right Join

LOAD ID,

     Max(IDVersion) as IDVersion

Resident tabInput

Group By ID;

hope this helps

regards

Marco

View solution in original post

24 Replies
maxgro
MVP
MVP

RESULT

EDIT: sorry,  I used 1352 instead of 1353, the script is the same, just change the number

1.png

SCRIPT

source:

load * inline [

ID, Year, ProductID, Sales, IDVersion

1352,2012,10115,3,2

1352,2012,10116,4,2

1352,2012,13252,1,1

1352,2012,10116,1,1

1352,2012,10115,3,3

1352,2012,10116,4,3

1352,2012,13252,4,3

];

final:

NoConcatenate load

  *

Resident source

where ProductID <> Peek(ProductID)

order by ProductID, IDVersion desc;

drop Table source;

ronald_gdi
Contributor III
Contributor III

Hi

The function MAX is a good soluction to use into the chart.

pratap6699
Creator
Creator

LOAD

ID,

YEAR,

PRODUCTID,

if(IDversion=3,IDversion,'optional')as IDVersion from path;

MarcoWedel

Hi,

another solution could be:

QlikCommunity_Thread_166605_Pic1.JPG

tabInput:

LOAD * Inline [

ID, Year, ProductID, Sales, IDVersion

1353,2012,10115,3,2

1353,2012,10116,4,2

1353,2012,13252,1,1

1353,2012,10116,1,1

1353,2012,10115,3,3

1353,2012,10116,4,3

1353,2012,13252,4,3

];

Right Join

LOAD ProductID,

    Max(IDVersion) as IDVersion

Resident tabInput

Group By ProductID;

hope this helps

regards

Marco

Anonymous
Not applicable
Author

I'm sorry, I didn't explain myself as well as I should have.

This is another set of data that explains the situation a different but more accurate way:

I have the following data set:

VersionID.PNG

What I want to do, is get all the product ID's that have the highest ID version.

So according to the data set, with the correct script, I should get:

VersionID2.PNG

The solution could work on a script level or a front-end level.


mdmukramali
Specialist III
Specialist III

Dear Francisco,

Instead of attaching the image can you attach the data so that we can load the data into Qlikview to help you.

VersionID.PNG

Like :

 

IDYearProductIDSalesIDVersion
135320121011532
135320121011643
135320121325211

etc.

Thanks,

Mukram

maxgro
MVP
MVP

why do you have the same product (10115, ...) in 2 rows?

do you want the max ID version by

.- product

- or product and year

- or product and id

- or ID version (highest is 10)

- or ????

and please, add some data (excel, txt, qvd, ....)

Anonymous
Not applicable
Author

  So sorry, here it's the data:

IDYearProductIDSales IDVersion
135320121011532
135320121011642
135320121325211
135320121011611
135320121011533
135320121011643
135320121325243
136320121011534
136320121012222
136320121325214
136320121012214
136320121325253
136320121011521
1863200018856410
186320001235511
186320007845623
186320001111132
1863200012345210
186320001885614
1863200011111310
186320001111118

Result:

 

IDYearProductIDSales IDVersion
135320121011533
135320121011643
135320121325243
136320121011534
136320121325214
136320121012214
1863200018856410
1863200012345210
1863200011111310

About the question:

The result should be grouped by ID and ProductID

Thanks Alot

MarcoWedel

Right Join 

LOAD ID, ProductID, 

    Max(IDVersion) as IDVersion 

Resident tabInput 

Group By ID, ProductID;