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: 
greend21
Creator III
Creator III

Max in IF statement in load

I am trying to put the below calculation into my load so I can then use this flag in set analysis. Can this not be done? I keep receiving errors. I didn't think I would need a group by since Max is within the IF.

If(ReportDate>=Max(ReportDate)-5,1,0) as CADateFlag

1 Solution

Accepted Solutions
MK_QSL
MVP
MVP

Temp:

Load Date(CEMinDt-5) as MaxDate;

SQL SELECT Max(ReportDate) as CEMinDt

FROM CSSC_Sequence_SIT.dbo.rptCE_ORMaster;

View solution in original post

12 Replies
olivierrobin
Specialist III
Specialist III

hello,

in a load you're working at row level

you should calculate the max valeur first in one load

and use the value in the 2nd one

MK_QSL
MVP
MVP

You have to do something like below

Temp:
Load Date(Max(ReportDate)-5) as MaxDate Resident YourTableName;

Let vMaxDate = Peek('MaxDate');

Drop Table Temp;

Now you can use

If(ReportDate>='$(vMaxDate)',1,0) as CADateFlag

greend21
Creator III
Creator III
Author

It is assigning 1 to all report dates. Any idea why? I followed your instructions and it seems like it should work.

Temp:
SQL SELECT Max(ReportDate)-5 CEMinDt
FROM CSSC_Sequence_SIT.dbo.rptCE_ORMaster;
LET vCEMinDt = Peek('CEMinDt');
Drop Table Temp;

Load *,
IF(ReportDate>='$(vCEMinDt)',1,0) as CEDateFlag
;
Table1:
SQL SELECT ReportDate,
BackLog CEBacklog,
MultiNational CEMultinational,
CreditDebit CECreditDebit,
CE_EfftAge_Days,
CE_BillAge_Days,
CE_DueAge_Days,
CE_YTDTotalAmt,
OR_90PlusDayYTDAmt,
    OR_EfftAge_0_30Amt,
OR_EfftAge_31_60Amt,
OR_EfftAge_61_90Amt,
OR_EfftAge_91Amt,
OR_EfftAge_0_30Cnt,
OR_EfftAge_31_60Cnt,
OR_EfftAge_61_90Cnt,
OR_EfftAge_91Cnt
FROM CSSC_Sequence_SIT.dbo.rptCE_ORMaster;

shiveshsingh
Master
Master

Max(ReportDate) --> This will give you a integer.


Better to store value in some variable as suggested by Manish and then use it further.

MK_QSL
MVP
MVP

Temp:

Load Date(CEMinDt-5) as MaxDate;

SQL SELECT Max(ReportDate) as CEMinDt

FROM CSSC_Sequence_SIT.dbo.rptCE_ORMaster;

olivierrobin
Specialist III
Specialist III

check the format of the dates between tour database and Qlik

greend21
Creator III
Creator III
Author

I checked the temp table before I dropped it and it doesn't return an integer, it returns the date. It returns the correct date. I did store it in a variable as suggested.

shiveshsingh
Master
Master

Hi

Put like this

SQL SELECT Date(Max(ReportDate)-5)

olivierrobin
Specialist III
Specialist III

be careful that '$(vMaxDate)' returns a string and not a value in a date format

you should have to use date functions in QV or SQL to have two values of same type