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

set analysis - date condition

Hi, I have code_dt_me (month in which code is placed on an account) and trandate_me (transaction month for the accounts) in my data. There is a sale amount corresponding to each trandate_me. I want to calculate the sum(Sale) amount happened in the month of code or after code date month for each code month.

  Example data:

For the accounts coded in month of 30sep2016, I want to calcualte the sum(prin_bal_at) for transaction month after code month. For accounts coded in sep'16 month, I want to track the transactions on those accounts from sep'16-jan'17. I should not include any transactions happened before sep'16. in the below data I should not include aug'16 transactions in the SUM.

code_dt_meTranDate_MEprin_bal_at
30SEP201628FEB20171124.49
30SEP201628FEB201711171.36
30SEP201630NOV201611569.12
30SEP201630NOV201611718.76
30SEP201630NOV201612103.61
30SEP201630NOV201616231.12
30SEP201630SEP2016114.78
30SEP201630SEP2016371.74
30SEP201630SEP2016429.21
30SEP201630SEP2016748.69
30SEP201631AUG2016443.21
30SEP201631AUG2016748.69
30SEP201631AUG20161550
30SEP201631AUG20162354.28
30SEP201631AUG20162501.78
30SEP201631DEC20168845.53
30SEP201631DEC201611171.36
30SEP201631JAN20171770.25
30SEP201631JAN20171844.76
30SEP201631JAN20171991.86
30SEP201631JAN20172354.28
30SEP201631OCT20161068.83
30SEP201631OCT20161198.6
30SEP201631OCT20161199.4

 

I tried this expression but this is not working:

if(date(date#(code_dt_me, 'DDMMMYYYY'),'YYYYMMDD')<=date(date#(TranDate_ME, 'DDMMMYYYY'),'YYYYMMDD'),sum({<CODE_DT_YR_MTH={201609}>}Amount*-1) )

I need help with the expression.

Thanks

8 Replies
adamdavi3s
Master
Master

Maybe this?

sum({<CODE_DT_YR_MTH={201609},(date(date#(code_dt_me, 'DDMMMYYYY'),'YYYYMMDD')={"<=$(=date(date#(TranDate_ME, DDMMMYYYY'),'YYYYMMDD'))"}>}Amount*-1) )

phoenix
Creator
Creator
Author

sum({<CODE_DT_YR_MTH={201609},(date(date#(code_dt_me, 'DDMMMYYYY'),'YYYYMMDD')={"<=$(=date(date#(TranDate_ME, 'DDMMMYYYY'),'YYYYMMDD'))"}>}Amount*-1))
Adam, thanks for the reply. T
his is giving me all null values.

phoenix
Creator
Creator
Author

when I use this in text box I am getting  null value=date(date#(code_dt_me, 'DDMMMYYYY'),'YYYYMMDD')

but if I use =max(=date(date#(code_dt_me, 'DDMMMYYYY'),'YYYYMMDD') ) I get 20170131. Not able to understand the logic behind date conversion.

adamdavi3s
Master
Master

This logic is because in the text box its trying to calculate for multiple dates, when you max it then it can return a result because there is only one value.


Sorry manic afternoon but will try and pick this one up again later

Anil_Babu_Samineni

For 1st one you never get any date due to you don't have Aggregation here

And 2nd one should give Max of Date. Here what you are not understand?

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
phoenix
Creator
Creator
Author


test:
load * inline [
Amount, CODE_DT_YR_MTH, code_dt_me, TranDate_ME, Trans_YR_MTH
-412.59, 201609, 30SEP2016, 31AUG2016, 201608
-325.18, 201609, 30SEP2016, 31AUG2016, 201608
-285, 201609, 30SEP2016, 31AUG2016, 201608
-350, 201609, 30SEP2016, 30SEP2016, 201609
-301.37, 201609, 30SEP2016, 30SEP2016, 201609
-83.11, 201609, 30SEP2016, 31OCT2016, 201610
-82.59, 201609, 30SEP2016, 31OCT2016, 201610
-50.13, 201609, 30SEP2016, 31OCT2016, 201610
-1.31, 201609, 30SEP2016, 31OCT2016, 201610
-793.45, 201609, 30SEP2016, 30NOV2016, 201611
-551, 201609, 30SEP2016, 30NOV2016, 201611
-500, 201609, 30SEP2016, 30NOV2016, 201611
-50, 201609, 30SEP2016, 31DEC2016, 201612
-47, 201609, 30SEP2016, 31DEC2016, 201612
-1250, 201609, 30SEP2016, 31JAN2017, 201701
-1000, 201609, 30SEP2016, 31JAN2017, 201701
-941.28, 201609, 30SEP2016, 31JAN2017, 201701
-400, 201609, 30SEP2016, 31JAN2017, 201701
]
;


sasiparupudi1
Master III
Master III

Create a flag in the script

test:

LOAD

Date(Date#(CODE_DT_YR_MTH,'YYYYMM'),'YYYYMM') as CODE_DT_YR_MTH,

code_dt_me,

TranDate_ME,

Date(Date#(Trans_YR_MTH,'YYYYMM'),'YYYYMM') as Trans_YR_MTH,

if(Trans_YR_MTH<CODE_DT_YR_MTH,0,1) as flag,

Amount

;

load * inline [

Amount, CODE_DT_YR_MTH, code_dt_me, TranDate_ME, Trans_YR_MTH

-412.59, 201609, 30SEP2016, 31AUG2016, 201608

-325.18, 201609, 30SEP2016, 31AUG2016, 201608

-285, 201609, 30SEP2016, 31AUG2016, 201608

-350, 201609, 30SEP2016, 30SEP2016, 201609

-301.37, 201609, 30SEP2016, 30SEP2016, 201609

-83.11, 201609, 30SEP2016, 31OCT2016, 201610

-82.59, 201609, 30SEP2016, 31OCT2016, 201610

-50.13, 201609, 30SEP2016, 31OCT2016, 201610

-1.31, 201609, 30SEP2016, 31OCT2016, 201610

-793.45, 201609, 30SEP2016, 30NOV2016, 201611

-551, 201609, 30SEP2016, 30NOV2016, 201611

-500, 201609, 30SEP2016, 30NOV2016, 201611

-50, 201609, 30SEP2016, 31DEC2016, 201612

-47, 201609, 30SEP2016, 31DEC2016, 201612

-1250, 201609, 30SEP2016, 31JAN2017, 201701

-1000, 201609, 30SEP2016, 31JAN2017, 201701

-941.28, 201609, 30SEP2016, 31JAN2017, 201701

-400, 201609, 30SEP2016, 31JAN2017, 201701

];

and in the set analysis

sum({<flag={1}>}Amount)

hth

Sasi

phoenix
Creator
Creator
Author

Hi Sasidhar, thanks for your reply. that helped. how to approach this if those two date fields are in different tables? I have a star schema data model I am not joining the tables.