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

Get the corresponding Value of the Max Month in all the records

Hi,

I have a requirement, where I want to get the Value against the Max of the Month for all the records. I am able to achieve this using a straight chart, with an expression - 

Aggr(If(Month = Max(TOTAL <ID> Month), Sum(Value)), ID, Month)

However, I want to achieve the same using QlikView script, without using any charts or set analysis. Any suggestions please?

This is my input data. 

ID Month Value
1 4 123
1 5 123
1 6 777
1 7 777
1 8 777
2 8 4245
2 9 4245
2 10 2756
2 11 2756
3 9 498
3 10 498
3 11 498
3 12 999

 

And, this is my output. 

ID Month Value
1 4 777
1 5 777
1 6 777
1 7 777
1 8 777
2 8 2756
2 9 2756
2 10 2756
2 11 2756
3 9 999
3 10 999
3 11 999
3 12 999

 

Thank you!

SK

Labels (1)
2 Solutions

Accepted Solutions
Aurelien_Martinez
Partner - Specialist II
Partner - Specialist II

Hi,

With your example :

 

amartinez35_0-1662041325189.png

 

data:
LOAD
*
Inline [
ID, Month, Value
1, 4, 123
1, 5, 123
1, 6, 777
1, 7, 777
1, 8, 777
2, 8, 4245
2, 9, 4245
2, 10, 2756
2, 11, 2756
3, 9, 498
3, 10, 498
3, 11, 498
3, 12, 999
];


LOAD
ID,
Month,
Value,
If(ID=Peek(ID),
Peek(NewValue),
Value
) as NewValue
Resident data
Order By
ID,
Month desc
;

DROP Table data;

 

Aurélien

Help users find answers! Don't forget to mark a solution that worked for you!

View solution in original post

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I would recommend FirstSortedValue. 

Join (data)
Load
  ID,
  FirstSortedValue(Value, -Month) as NewValue
Resident data
Group By ID
; 

You can also use FirstSortedValue as a chart expression. 

-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com

View solution in original post

2 Replies
Aurelien_Martinez
Partner - Specialist II
Partner - Specialist II

Hi,

With your example :

 

amartinez35_0-1662041325189.png

 

data:
LOAD
*
Inline [
ID, Month, Value
1, 4, 123
1, 5, 123
1, 6, 777
1, 7, 777
1, 8, 777
2, 8, 4245
2, 9, 4245
2, 10, 2756
2, 11, 2756
3, 9, 498
3, 10, 498
3, 11, 498
3, 12, 999
];


LOAD
ID,
Month,
Value,
If(ID=Peek(ID),
Peek(NewValue),
Value
) as NewValue
Resident data
Order By
ID,
Month desc
;

DROP Table data;

 

Aurélien

Help users find answers! Don't forget to mark a solution that worked for you!
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I would recommend FirstSortedValue. 

Join (data)
Load
  ID,
  FirstSortedValue(Value, -Month) as NewValue
Resident data
Group By ID
; 

You can also use FirstSortedValue as a chart expression. 

-Rob
http://www.easyqlik.com
http://masterssummit.com
http://qlikviewcookbook.com