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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
phongnnguyen
Contributor II
Contributor II

Calculate previous value with set analysis

Hi guys,

I have a problem with  my set analysis. My data like this:

AEIDClientidTradedateTypeAmount
AE1001z000101/01/2017Reactive1000
AE1001z000131/12/2017Old2000
AE1001z000201/01/2017Old3000
AE1001z000301/01/2017Old4000
AE1001z000231/12/2017Old5000
AE1001z000331/12/2017Old6000
AE1001z000610/09/2017New200
AE1001z000803/02/2018New100
AE1001Z000906/05/2017Reactive4000

I want to have result total Amount of AE1 in 2017 with LAST Type is "Old".  It's mean AE1 = 21000 ( in this case ClientID : 001Z0001 has 2 types: Reactive and Old, but take LAST type( newest ) is OLD)

I use this set analysis but it isn't my expectation

sum(

{<TradeDate={">=$(=date(yearstart (max(TradeDate), -1),'YYYY-MM-DD'))<=$(=date(yearend(max(TradeDate),-1),'YYYY-MM-DD'))"}

    ,Type={'Old'}

    >} Amount)

Please give me the solution with this trouble. Thanks for your help

5 Replies
niclaz79
Partner - Creator III
Partner - Creator III

Sum({<Type -={'New'}>}if(Year(TradeDate) = 2017,Amount))

phongnnguyen
Contributor II
Contributor II
Author

Hi Niclas,

I understand your set analysis, but it is not my expectation. I have edit the data, Actually, Just sum OLD LAST status. your code will be sum all row without New

raman_rastogi
Partner - Creator III
Partner - Creator III

Hi Phong

Try This

Sum({< Type={'Old'},Tradedate ={">=$(=YearStart(max(Tradedate_N),-1)) <=$(=YearEnd(max(Tradedate_N),-1))"} >}Amount)

Best

Ramam Rastogi

tresesco
MVP
MVP

What is your expected output from the sample data above? Like this?

Capture.JPG

If so, try like:

FirstSortedValue( {< Type={'Old'},Tradedate ={">=$(=YearStart(max(Tradedate_N),-1)) <=$(=YearEnd(max(Tradedate_N),-1))"}>} Aggr(Sum(Amount),AEID,Clientid,Tradedate), - Tradedate)



balabhaskarqlik

May be this:

Sum({<Type={'Old'},Tradedate ={">=$(=YearStart(max(Tradedate),-1)) <=$(=YearEnd(max(Tradedate),-1))"}>} Aggr(Sum(Amount),Clientid,Tradedate))