Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Get the last revision value

Hi all,

I am very new to qlikview, I need help on the the following case.

I have a set of data in table "Cost"

YearMonthTypeCompany CodeReport numberAmount
20171ERP1001001/ABCD-1350
20171EML1001001/ABCD-120
20171ERP1002001/ABCD-1300
20172ERP1001002/ABCD-1325
20172EML1001002/ABCD-120
20172ERP1002002/ABCD-1300
20171ERP1001002/ABCD-1325 *
20173ERP1001003/ABC-1330
20173EML1001003/ABC-120
20173ERP1002003/ABC-1300
20171ERP1001003/ABC-1330**
20172ERP1001003/ABC-1330**

* is the first revision of ERP cost for month 1 of company 1001

** is the second revision of ERP cost for month 1 and 2 of company 1001

The final report is expected something like this:

YearMonthTypeCompany CodeReport numberAmount
20171EML1001001/ABCD-120
20171ERP1002001/ABCD-1300
20172EML1001002/ABCD-120
20172ERP1002002/ABCD-1300
20173ERP1001003/ABCD-1330
20173EML1001003/ABCD-120
20173ERP1002003/ABC-1300
20171ERP1001003/ABC-1330
20172ERP1001003/ABC-1330

The final report shows report number and amount of the latest revisions, latest cost revision may not always be lower or higher than the previous ones.

I try to use max(amount) but it will show the original cost value 350.

please help.

thank you.

2 Replies
Or
MVP
MVP

Your data above isn't entirely consistent with the expected output below (e.g. the Month = 3 rows have the wrong report number, if I understand the data correctly). However, for the sake of trying to answer, I'm assuming that's an error and the Report number can be used to determine what is the latest revision.

At the expression level, you could try something like:

sum(Amount * If([ReportNumber] = aggr(max([Report Number]),Year,Month,Type,[Company Code]),1))

Ideally, you should flag rows that belong to the latest revision at the script level using a similar mechanism - you can group based on the key fields and use something along the lines of having(Report Number = Max(Report Number). Set this flag to 1 if true, null if not, and multiply by the flag or use it in set analysis as you prefer.

Anonymous
Not applicable
Author

My mistake. the final report should be like this:

YearMonthTypeCompany CodeReport numberAmount
20171ERP1001003/ABC-1330
20171EML1001001/ABCD-120
20171ERP1002001/ABCD-1300
20172ERP1001003/ABC-1330
20172EML1001002/ABCD-120
20172ERP1002002/ABCD-1300
20173ERP1001003/ABC-1330
20173EML1001003/ABC-120
20173ERP1002003/ABC-1300

So if there's a latest update for certain period of a type the report shows the latest report number and the amount.

thank you.