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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Yi_DE
Contributor II
Contributor II

FirstSortedValue of previous year

Hi Guys, i get 55 for firm A using 

 

 

 

 

FirstSortedValue(measure, key_date)

 

 

 

 

while i select January 2024 and Firm A in my app.

I also want to get the 2023 value as comparison using

 

 

 

 

FirstSortedValue(measure, AddYears(key_date, -1)

 

 

 

 

. This however didn't work. Then i tried set analysis to preselect the data to analyse like 

 

 

 

 

FirstSortedValue({<key_date= {">=$(=Date(AddYears(Min(key_date), -1))) <=$(=Date(AddYears(Max(key_date), -1)))"} measure, key_date)

 

 

 

 

that didn't work as well.

Following an simplified example of the data. Can someone help?

key_date firm measure
01.01.2023 A 100
01.01.2023 B 5
01.01.2023 C 200
02.01.2023 A 10
02.01.2023 B 20
02.01.2023 C 3
   
31.01.2023 A 33
   
01.01.2024 A 55
01.01.2024 B 2
01.01.2024 C 43
02.01.2024 A 67
02.01.2024 B 3
02.01.2024 C 1
   
31.01.2024 A 5
Labels (1)
1 Solution

Accepted Solutions
Yi_DE
Contributor II
Contributor II
Author

I finally get it to work with this 

{<[key_date.autoCalendar.Year]={"$(=Min(Year(key_date)) - 1)"}>} firstsortedvalue(measure, key_date)

, but i don't really understand why ...

View solution in original post

5 Replies
Kushal_Chawda
MVP
MVP

@Yi_DE  what is expected output?

Yi_DE
Contributor II
Contributor II
Author

Hi @Kushal_Chawda , the expected output is 100, the top line in the table.

Kushal_Chawda
MVP
MVP

@Yi_DE  I don't think you need firstsorted value. You can use below set

=sum({<key_date={"$(=date(addyears(min(key_date),-1)))"}>} measure)

Yi_DE
Contributor II
Contributor II
Author

@Kushal_Chawda This approach returns 0 as result, even though the key_date has the correct value of 01.01.2023

Yi_DE
Contributor II
Contributor II
Author

I finally get it to work with this 

{<[key_date.autoCalendar.Year]={"$(=Min(Year(key_date)) - 1)"}>} firstsortedvalue(measure, key_date)

, but i don't really understand why ...