Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Discover how organizations are unlocking new revenue streams: Watch here
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Selecting last value with expression

Hi,

I have an SQL table with salary information:

per_idsalarystart_period
1100201101
1120201204
1140201402

per_id: Person ID

salary: the salary

start_period: year and month (yyyyMM) when the salary changed.

I'd like to put in a table the salary for a given period, for exemple 201308.

I can do this in SQL but I have no cloue on how to put this value in a table when I have selected the period.

This is the SQL query I would use:

SELECT top 1 per_id

     ,salary

     ,start_period

FROM salary

WHERE per_id=1

     and start_period<=201308

ORDER BY start_period DESC

thank you!

Diego

1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Use per_id as your Dimension. For your expression:

=FirstSortedValue(salary,-start_period)

-Rob

http://masterssummit.com

http://robwunderlich.com

View solution in original post

3 Replies
swuehl
MVP
MVP

Try something like

INPUT:

LOAD per_id,

     salary,

     start_period

FROM

[http://community.qlik.com/thread/119681]

(html, codepage is 1252, embedded labels, table is @1);

LOAD per_id,

        FirstValue(salary) as CurrentSalary

Resident INPUT

where start_period <= 201308

Group by per_id

order by start_period desc;

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Use per_id as your Dimension. For your expression:

=FirstSortedValue(salary,-start_period)

-Rob

http://masterssummit.com

http://robwunderlich.com

Not applicable
Author

Just what I was looking for, works great! Thank you very much!